2024-03-14 07:36:19 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('assign', {
|
|
|
|
description: 'Assign a collection',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
http: {
|
|
|
|
path: `/assign`,
|
|
|
|
verb: 'POST'
|
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.assign = async(ctx, options) => {
|
|
|
|
const userId = ctx.req.accessToken.userId;
|
|
|
|
const myOptions = {userId};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2024-07-23 08:21:09 +00:00
|
|
|
const result = await Self.rawSql(`
|
|
|
|
CALL vn.collection_assign(?, @vCollectionFk);
|
|
|
|
SELECT @vCollectionFk collectionFk
|
|
|
|
`, [userId], myOptions);
|
|
|
|
|
|
|
|
// Por si entra en el SELECT FOR UPDATE y retorna un array más
|
2024-07-23 08:48:12 +00:00
|
|
|
const collectionFk = result[2]?.[0]?.collectionFk || result[3]?.[0]?.collectionFk;
|
2024-03-14 07:36:19 +00:00
|
|
|
|
|
|
|
if (!collectionFk) throw new UserError('There are not picking tickets');
|
|
|
|
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
|
|
|
|
|
|
|
return collectionFk;
|
|
|
|
};
|
|
|
|
};
|