2019-08-09 17:11:24 +03:00
|
|
|
// NOTE: We must not cache references to membersService.api
|
|
|
|
// as it is a getter and may change during runtime.
|
|
|
|
const membersService = require('../../services/members');
|
2019-09-03 07:10:32 +03:00
|
|
|
const common = require('../../lib/common');
|
2019-08-09 17:11:24 +03:00
|
|
|
|
|
|
|
const members = {
|
|
|
|
docName: 'members',
|
|
|
|
browse: {
|
|
|
|
options: [
|
|
|
|
'limit',
|
|
|
|
'fields',
|
|
|
|
'filter',
|
|
|
|
'order',
|
|
|
|
'debug',
|
|
|
|
'page'
|
|
|
|
],
|
|
|
|
permissions: true,
|
|
|
|
validation: {},
|
|
|
|
query(frame) {
|
|
|
|
return membersService.api.members.list(frame.options);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
read: {
|
|
|
|
headers: {},
|
|
|
|
data: [
|
|
|
|
'id',
|
|
|
|
'email'
|
|
|
|
],
|
|
|
|
validation: {},
|
|
|
|
permissions: true,
|
2019-09-03 07:10:32 +03:00
|
|
|
async query(frame) {
|
|
|
|
const member = await membersService.api.members.get(frame.data, frame.options);
|
|
|
|
if (!member) {
|
|
|
|
throw new common.errors.NotFoundError({
|
|
|
|
message: common.i18n.t('errors.api.members.memberNotFound')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return member;
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-03 12:15:50 +03:00
|
|
|
add: {
|
|
|
|
statusCode: 201,
|
|
|
|
headers: {},
|
|
|
|
options: [
|
|
|
|
'send_email',
|
|
|
|
'email_type'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
data: {
|
|
|
|
email: {required: true}
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
email_type: {
|
|
|
|
values: ['signin', 'signup', 'subscribe']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
|
|
|
const member = await membersService.api.members.create(frame.data.members[0], {
|
|
|
|
sendEmail: frame.options.send_email,
|
|
|
|
emailType: frame.options.email_type
|
|
|
|
});
|
|
|
|
|
|
|
|
return member;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-03 14:38:22 +03:00
|
|
|
edit: {
|
|
|
|
statusCode: 200,
|
|
|
|
headers: {},
|
|
|
|
options: [
|
|
|
|
'id'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
id: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
|
|
|
async query(frame) {
|
|
|
|
const member = await membersService.api.members.update(frame.data.members[0], frame.options);
|
|
|
|
return member;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-08-09 17:11:24 +03:00
|
|
|
destroy: {
|
|
|
|
statusCode: 204,
|
|
|
|
headers: {},
|
|
|
|
options: [
|
|
|
|
'id'
|
|
|
|
],
|
|
|
|
validation: {
|
|
|
|
options: {
|
|
|
|
id: {
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
permissions: true,
|
2019-10-02 11:25:49 +03:00
|
|
|
async query(frame) {
|
2019-08-09 17:11:24 +03:00
|
|
|
frame.options.require = true;
|
2019-10-02 11:25:49 +03:00
|
|
|
await membersService.api.members.destroy(frame.options);
|
|
|
|
return null;
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = members;
|