Merge pull request '5216-addExpeditionState' (!1815) from 5216-addExpeditionState into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1815
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Jorge Penadés 2023-10-30 12:52:21 +00:00
commit d2468033ea
3 changed files with 21 additions and 10 deletions

View File

@ -0,0 +1,13 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expeditionState_BeforeInsert`
BEFORE INSERT ON `expeditionState`
FOR EACH ROW
BEGIN
SET NEW.userFk = IFNULL(NEW.userFk, account.myUser_getId());
END$$
DELIMITER ;

View File

@ -1,7 +1,7 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('addExpeditionState', {
Self.remoteMethodCtx('addExpeditionState', {
description: 'Update an expedition state',
accessType: 'WRITE',
accepts: [
@ -12,18 +12,15 @@ module.exports = Self => {
description: 'Array of objects containing expeditionFk and stateCode'
}
],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/addExpeditionState`,
verb: 'post'
}
});
Self.addExpeditionState = async(expeditions, options) => {
Self.addExpeditionState = async(ctx, expeditions, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
let tx;
const myOptions = {};
if (typeof options == 'object')
@ -51,6 +48,7 @@ module.exports = Self => {
await models.ExpeditionState.create({
expeditionFk: expedition.expeditionFk,
typeFk,
userFk: userId,
}, myOptions);
}

View File

@ -1,9 +1,9 @@
const models = require('vn-loopback/server/server').models;
describe('expeditionState addExpeditionState()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should update the expedition states', async() => {
const tx = await models.ExpeditionState.beginTransaction({});
try {
const options = {transaction: tx};
const payload = [
@ -13,7 +13,7 @@ describe('expeditionState addExpeditionState()', () => {
},
];
await models.ExpeditionState.addExpeditionState(payload, options);
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
const expeditionState = await models.ExpeditionState.findOne({
where: {id: 5}
@ -39,7 +39,7 @@ describe('expeditionState addExpeditionState()', () => {
stateCode: 'DUMMY'
}
];
await models.ExpeditionState.addExpeditionState(payload, options);
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
await tx.rollback();
} catch (e) {
@ -62,7 +62,7 @@ describe('expeditionState addExpeditionState()', () => {
}
];
await models.ExpeditionState.addExpeditionState(payload, options);
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
await tx.rollback();
} catch (e) {