30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
|
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'],
|
||
|
root: true
|
||
|
},
|
||
|
});
|
||
|
|
||
|
Self.assignCollection = async(ctx, options) => {
|
||
|
const userId = ctx.req.accessToken.userId;
|
||
|
const myOptions = {userId};
|
||
|
|
||
|
if (typeof options == 'object')
|
||
|
Object.assign(myOptions, options);
|
||
|
const [info, info2, [{'@vCollectionFk': collectionFk}]] = await Self.rawSql(
|
||
|
'CALL vn.collection_getAssigned(?, @vCollectionFk);SELECT @vCollectionFk', [userId], myOptions);
|
||
|
if (!collectionFk) throw new UserError('There are not picking tickets');
|
||
|
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
||
|
|
||
|
return collectionFk;
|
||
|
};
|
||
|
};
|