2022-03-28 17:24:51 +02:00
|
|
|
const models = require('../../models');
|
2022-04-22 17:42:52 +02:00
|
|
|
const allowedIncludes = ['count.posts', 'count.members'];
|
2022-04-21 09:59:44 +02:00
|
|
|
|
2022-04-22 13:20:44 +01:00
|
|
|
const newslettersService = require('../../services/newsletters');
|
2022-03-28 17:24:51 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
docName: 'newsletters',
|
|
|
|
|
|
|
|
browse: {
|
|
|
|
options: [
|
2022-04-22 17:42:52 +02:00
|
|
|
'include',
|
2022-03-28 17:24:51 +02:00
|
|
|
'filter',
|
|
|
|
'fields',
|
|
|
|
'limit',
|
|
|
|
'order',
|
|
|
|
'page'
|
|
|
|
],
|
2022-04-22 17:42:52 +02:00
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
include: {
|
|
|
|
values: allowedIncludes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-28 17:24:51 +02:00
|
|
|
permissions: true,
|
|
|
|
query(frame) {
|
|
|
|
return models.Newsletter.findPage(frame.options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-04-21 09:59:44 +02:00
|
|
|
read: {
|
|
|
|
options: [
|
2022-04-22 17:42:52 +02:00
|
|
|
'include',
|
2022-04-21 09:59:44 +02:00
|
|
|
'fields',
|
|
|
|
'debug',
|
|
|
|
// NOTE: only for internal context
|
|
|
|
'forUpdate',
|
|
|
|
'transacting'
|
|
|
|
],
|
|
|
|
data: [
|
|
|
|
'id',
|
|
|
|
'slug',
|
|
|
|
'uuid'
|
|
|
|
],
|
2022-04-22 17:42:52 +02:00
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
include: {
|
|
|
|
values: allowedIncludes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-04-21 09:59:44 +02:00
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
2022-05-05 11:20:15 +02:00
|
|
|
return newslettersService.read(frame.data, frame.options);
|
2022-04-21 09:59:44 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-28 17:24:51 +02:00
|
|
|
add: {
|
|
|
|
statusCode: 201,
|
2022-04-26 18:06:41 +05:30
|
|
|
headers: {
|
|
|
|
cacheInvalidate: true
|
|
|
|
},
|
2022-04-22 17:42:52 +02:00
|
|
|
options: [
|
2022-04-25 21:07:46 +01:00
|
|
|
'include',
|
|
|
|
'opt_in_existing'
|
2022-04-22 17:42:52 +02:00
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
include: {
|
|
|
|
values: allowedIncludes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-28 17:24:51 +02:00
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
2022-04-22 13:20:44 +01:00
|
|
|
return newslettersService.add(frame.data.newsletters[0], frame.options);
|
2022-03-28 17:24:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
edit: {
|
2022-04-26 18:06:41 +05:30
|
|
|
headers: {
|
|
|
|
cacheInvalidate: true
|
|
|
|
},
|
2022-03-28 17:24:51 +02:00
|
|
|
options: [
|
2022-04-22 17:42:52 +02:00
|
|
|
'id',
|
|
|
|
'include'
|
2022-03-28 17:24:51 +02:00
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
id: {
|
|
|
|
required: true
|
2022-04-22 17:42:52 +02:00
|
|
|
},
|
|
|
|
include: {
|
|
|
|
values: allowedIncludes
|
2022-03-28 17:24:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
2022-04-22 13:20:44 +01:00
|
|
|
return newslettersService.edit(frame.data.newsletters[0], frame.options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
verifyPropertyUpdate: {
|
|
|
|
permissions: {
|
|
|
|
method: 'edit'
|
|
|
|
},
|
|
|
|
data: [
|
|
|
|
'token'
|
|
|
|
],
|
|
|
|
async query(frame) {
|
|
|
|
return newslettersService.verifyPropertyUpdate(frame.data.token);
|
2022-03-28 17:24:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|