'use strict'; /** * update-item controller */ const { createCoreController } = require('@strapi/strapi').factories; module.exports = createCoreController('api::update-item.update-item', ({ strapi }) => ({ async create(ctx) { ctx.request.body.data.submittedBy = ctx.state.user; ctx.request.body.data.SubmittedAt = new Date(); return super.create(ctx); }, async update(ctx) { // console.log(ctx.state.user.role.name); switch (ctx.state.user.role.name) { case 'Public': case 'Authenticated': case 'Contributor': // Remove operation should be intact ctx.request.body.data.updatedBy = ctx.state.user.id; ctx.request.body.data.UpdateSubmissionTimestamp = new Date(); break; case 'Maintainer': case 'Administrator': // Handle the review comment and // If ReviewAt field is null, should be set. Otherwise it continues; // Apply review operation // const entity = await strapi.service('api::update-item.update-item').findOne(ctx.params.id); // console.log(entity); ctx.request.body.data.reviewedBy = ctx.state.user.id; ctx.request.body.data.UpdateReviewTimestamp = new Date(); break; } return super.update(ctx); }, async updateReview(ctx) { console.log('update info') const response = await super.update(ctx); return response; } // async findAll(ctx) { // console.log(ctx); // return super.findAll(ctx, { populate: ['submittedBy', 'reviewedBy']}) // }, // async find(ctx) { // console.log(ctx); // return super.find(ctx, { populate: ['submittedBy', 'reviewedBy']}) // } }));