2019-08-31 04:07:25 +05:00
|
|
|
const Errors = {
|
2020-04-03 00:35:25 +05:00
|
|
|
EMAIL_ALREADY_IN_USE: {
|
|
|
|
emailAlreadyInUse: 'Email already in use',
|
|
|
|
},
|
|
|
|
USERNAME_ALREADY_IN_USE: {
|
|
|
|
usernameAlreadyInUse: 'Username already in use',
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
inputs: {
|
|
|
|
email: {
|
|
|
|
type: 'string',
|
|
|
|
isEmail: true,
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
2019-11-05 18:01:42 +05:00
|
|
|
required: true,
|
|
|
|
},
|
2020-04-03 00:35:25 +05:00
|
|
|
username: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
minLength: 3,
|
|
|
|
maxLength: 16,
|
2021-04-13 18:59:02 +05:00
|
|
|
regex: /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/,
|
2020-04-03 00:35:25 +05:00
|
|
|
allowNull: true,
|
|
|
|
},
|
2020-04-09 18:27:28 +05:00
|
|
|
phone: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
allowNull: true,
|
|
|
|
},
|
|
|
|
organization: {
|
|
|
|
type: 'string',
|
|
|
|
isNotEmptyString: true,
|
|
|
|
allowNull: true,
|
|
|
|
},
|
2020-04-10 00:11:34 +05:00
|
|
|
subscribeToOwnCards: {
|
|
|
|
type: 'boolean',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
2020-04-03 00:35:25 +05:00
|
|
|
emailAlreadyInUse: {
|
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
|
|
|
usernameAlreadyInUse: {
|
2019-11-05 18:01:42 +05:00
|
|
|
responseType: 'conflict',
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
},
|
|
|
|
|
2019-11-05 18:01:42 +05:00
|
|
|
async fn(inputs, exits) {
|
2020-04-09 18:27:28 +05:00
|
|
|
const values = _.pick(inputs, [
|
|
|
|
'email',
|
|
|
|
'password',
|
|
|
|
'name',
|
|
|
|
'username',
|
|
|
|
'phone',
|
|
|
|
'organization',
|
2020-04-10 00:11:34 +05:00
|
|
|
'subscribeToOwnCards',
|
2020-04-09 18:27:28 +05:00
|
|
|
]);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const user = await sails.helpers
|
|
|
|
.createUser(values, this.req)
|
2020-04-03 00:35:25 +05:00
|
|
|
.intercept('emailAlreadyInUse', () => Errors.EMAIL_ALREADY_IN_USE)
|
|
|
|
.intercept('usernameAlreadyInUse', () => Errors.USERNAME_ALREADY_IN_USE);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
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
|
|
|
};
|