Schema changed, findMany implemented

This commit is contained in:
j-weissen 2022-09-26 12:32:27 +02:00
parent f3dbc6d59b
commit 3786a803a6
2 changed files with 39 additions and 5 deletions

View file

@ -4,7 +4,8 @@
"info": { "info": {
"singularName": "note", "singularName": "note",
"pluralName": "notes", "pluralName": "notes",
"displayName": "note" "displayName": "note",
"description": ""
}, },
"options": { "options": {
"draftAndPublish": true "draftAndPublish": true
@ -20,8 +21,9 @@
}, },
"owners": { "owners": {
"type": "relation", "type": "relation",
"relation": "oneToMany", "relation": "manyToMany",
"target": "admin::user" "target": "plugin::users-permissions.user",
"inversedBy": "notes"
}, },
"lastViewed": { "lastViewed": {
"type": "datetime", "type": "datetime",

View file

@ -4,6 +4,38 @@
* note controller * 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")
}
}));
/**
*
*/