Merge pull request '5216-addExpeditionState' (!1815) from 5216-addExpeditionState into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1815 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
d2468033ea
|
@ -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 ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('addExpeditionState', {
|
Self.remoteMethodCtx('addExpeditionState', {
|
||||||
description: 'Update an expedition state',
|
description: 'Update an expedition state',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -12,18 +12,15 @@ module.exports = Self => {
|
||||||
description: 'Array of objects containing expeditionFk and stateCode'
|
description: 'Array of objects containing expeditionFk and stateCode'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
|
||||||
type: 'boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
http: {
|
||||||
path: `/addExpeditionState`,
|
path: `/addExpeditionState`,
|
||||||
verb: 'post'
|
verb: 'post'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.addExpeditionState = async(expeditions, options) => {
|
Self.addExpeditionState = async(ctx, expeditions, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
|
@ -51,6 +48,7 @@ module.exports = Self => {
|
||||||
await models.ExpeditionState.create({
|
await models.ExpeditionState.create({
|
||||||
expeditionFk: expedition.expeditionFk,
|
expeditionFk: expedition.expeditionFk,
|
||||||
typeFk,
|
typeFk,
|
||||||
|
userFk: userId,
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('expeditionState addExpeditionState()', () => {
|
describe('expeditionState addExpeditionState()', () => {
|
||||||
|
const ctx = {req: {accessToken: {userId: 9}}};
|
||||||
it('should update the expedition states', async() => {
|
it('should update the expedition states', async() => {
|
||||||
const tx = await models.ExpeditionState.beginTransaction({});
|
const tx = await models.ExpeditionState.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const payload = [
|
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({
|
const expeditionState = await models.ExpeditionState.findOne({
|
||||||
where: {id: 5}
|
where: {id: 5}
|
||||||
|
@ -39,7 +39,7 @@ describe('expeditionState addExpeditionState()', () => {
|
||||||
stateCode: 'DUMMY'
|
stateCode: 'DUMMY'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
await models.ExpeditionState.addExpeditionState(payload, options);
|
await models.ExpeditionState.addExpeditionState(ctx, payload, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} 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();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue