Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'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']})
// }
}));