Created
September 23, 2020 10:53
-
-
Save zorca/434445e2bf026ae7443e854c229113d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Read the documentation (https://strapi.io/documentation/v3.x/concepts/controllers.html#core-controllers) | |
* to customize this controller | |
*/ | |
module.exports = { | |
likeOne: async (ctx, next) => { | |
let user = ctx.state.user; | |
if (!user) { | |
return ctx.badRequest(null, [{ messages: [{ id: 'No authorization header was found' }] }]); | |
} | |
const { id } = ctx.params; | |
const currentUsermedia = await strapi.query('usermedias').findOne({ id: id }); | |
console.log(currentUsermedia.users); | |
let resultArray = []; | |
let updatedUsers = currentUsermedia.users.map(item => resultArray.push(item.id)); | |
updatedUsers.push(user.id); | |
console.log(updatedUsers); | |
await strapi.query('usermedias').update({ id: id }, { | |
users: updatedUsers, | |
}); | |
ctx.response.status = 200; | |
ctx.body = 'usermedia: ' + id + ' liked'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment