salix/back/methods/collection/assign.js

32 lines
979 B
JavaScript
Raw Normal View History

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