Schema changed, findMany implemented
This commit is contained in:
parent
f3dbc6d59b
commit
3786a803a6
2 changed files with 39 additions and 5 deletions
|
|
@ -4,7 +4,8 @@
|
|||
"info": {
|
||||
"singularName": "note",
|
||||
"pluralName": "notes",
|
||||
"displayName": "note"
|
||||
"displayName": "note",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
|
|
@ -20,8 +21,9 @@
|
|||
},
|
||||
"owners": {
|
||||
"type": "relation",
|
||||
"relation": "oneToMany",
|
||||
"target": "admin::user"
|
||||
"relation": "manyToMany",
|
||||
"target": "plugin::users-permissions.user",
|
||||
"inversedBy": "notes"
|
||||
},
|
||||
"lastViewed": {
|
||||
"type": "datetime",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,38 @@
|
|||
* note controller
|
||||
*/
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
const {createCoreController} = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreController('api::note.note');
|
||||
module.exports = createCoreController('api::note.note', ({strapi}) => ({
|
||||
/**
|
||||
* Gives all, to the user related, notes.
|
||||
* @param ctx
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async find(ctx) {
|
||||
const userId = ctx.state.user.id;
|
||||
|
||||
const entries = await strapi.entityService.findMany('api::note.note', {
|
||||
populate: ['owners'],
|
||||
filters: {
|
||||
owners: {
|
||||
id: userId
|
||||
}
|
||||
},
|
||||
sort: 'lastViewed'
|
||||
});
|
||||
return JSON.stringify(entries);
|
||||
},
|
||||
/**
|
||||
* Finds the note by id. Only returns the note when the user is assigned.
|
||||
* @param ctx
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async findOne(ctx) {
|
||||
console.log("findOne")
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue