2023-11-21 11:32:36 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('assignCollection', {
|
|
|
|
description: 'Assign a collection',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
http: {
|
|
|
|
path: `/assignCollection`,
|
|
|
|
verb: 'POST'
|
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
2024-01-17 12:57:57 +00:00
|
|
|
root: true
|
2023-11-21 11:32:36 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-25 11:14:14 +00:00
|
|
|
Self.assignCollection = async(ctx, options) => {
|
2023-11-21 11:32:36 +00:00
|
|
|
const userId = ctx.req.accessToken.userId;
|
2024-01-25 11:14:14 +00:00
|
|
|
const myOptions = {userId};
|
2023-11-21 11:32:36 +00:00
|
|
|
|
2024-01-25 11:14:14 +00:00
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId], myOptions);
|
2023-11-21 11:32:36 +00:00
|
|
|
|
|
|
|
const [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk');
|
|
|
|
const {'@vCollectionFk': collectionFk} = assignedCollection;
|
|
|
|
|
2024-01-30 15:07:33 +00:00
|
|
|
if (!collectionFk) throw new UserError('There are not picking tickets');
|
2024-01-25 11:14:14 +00:00
|
|
|
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
2023-11-21 11:32:36 +00:00
|
|
|
|
|
|
|
return collectionFk;
|
|
|
|
};
|
|
|
|
};
|