salix/back/methods/collection/assignCollection.js

35 lines
1.1 KiB
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('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
},
});
Self.assignCollection = async(ctx, options) => {
2023-11-21 11:32:36 +00:00
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
const $t = ctx.req.__;
2023-11-21 11:32:36 +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;
if (!collectionFk) throw new UserError($t('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;
};
};