2021-06-24 01:05:22 +05:00
|
|
|
const Errors = {
|
|
|
|
USER_NOT_FOUND: {
|
|
|
|
userNotFound: 'User not found',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const CURRENT_USER_ID = 'me';
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
module.exports = {
|
2021-06-24 01:05:22 +05:00
|
|
|
inputs: {
|
|
|
|
id: {
|
|
|
|
type: 'string',
|
|
|
|
regex: /^[0-9]+|me$/,
|
|
|
|
required: true,
|
|
|
|
},
|
2023-01-05 15:03:06 +01:00
|
|
|
subscribe: {
|
|
|
|
type: 'boolean',
|
|
|
|
},
|
2021-06-24 01:05:22 +05:00
|
|
|
},
|
|
|
|
|
|
|
|
exits: {
|
|
|
|
boardNotFound: {
|
|
|
|
responseType: 'notFound',
|
|
|
|
},
|
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
async fn(inputs) {
|
|
|
|
let user;
|
|
|
|
if (inputs.id === CURRENT_USER_ID) {
|
|
|
|
({ currentUser: user } = this.req);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2023-01-05 15:03:06 +01:00
|
|
|
if (inputs.subscribe && this.req.isSocket) {
|
|
|
|
sails.sockets.join(this.req, `user:${user.id}`);
|
2021-06-24 01:05:22 +05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user = await sails.helpers.users.getOne(inputs.id);
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
throw Errors.USER_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
return {
|
|
|
|
item: user,
|
|
|
|
};
|
2019-11-05 18:01:42 +05:00
|
|
|
},
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|