2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
|
|
|
USER_NOT_FOUND: {
|
2019-11-05 18:01:42 +05:00
|
|
|
notFound: 'User is not found',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
id: {
|
2019-10-10 02:51:54 +05:00
|
|
|
type: 'string',
|
|
|
|
regex: /^[0-9]+$/,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
|
|
|
notFound: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'notFound',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2019-08-31 04:07:25 +05:00
|
|
|
let user = await sails.helpers.getUser(inputs.id);
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
throw Errors.USER_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
user = await sails.helpers.deleteUser(user, this.req);
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
throw Errors.USER_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return exits.success({
|
2019-11-05 18:01:42 +05:00
|
|
|
item: user,
|
2019-08-31 04:07:25 +05:00
|
|
|
});
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|