This commit is contained in:
parent
24b6dcc606
commit
9f141238bc
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue