29 lines
901 B
JavaScript
29 lines
901 B
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'],
|
|
},
|
|
});
|
|
|
|
Self.assignCollection = async ctx => {
|
|
const userId = ctx.req.accessToken.userId;
|
|
|
|
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId]);
|
|
|
|
const [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk');
|
|
const {'@vCollectionFk': collectionFk} = assignedCollection;
|
|
|
|
if (!collectionFk) throw new UserError('No hay tickets para sacar');
|
|
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk]);
|
|
|
|
return collectionFk;
|
|
};
|
|
};
|