Changes
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2a2e276c6b
commit
a4d2c531a3
|
@ -1,8 +1,8 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('import', {
|
||||
description: 'Imports the buys from a JSON file',
|
||||
Self.remoteMethodCtx('importBuys', {
|
||||
description: 'Imports the buys from a list',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
|
@ -11,6 +11,11 @@ module.exports = Self => {
|
|||
description: 'The entry id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'options',
|
||||
type: 'object',
|
||||
description: 'Callback options',
|
||||
},
|
||||
{
|
||||
arg: 'ref',
|
||||
type: 'string',
|
||||
|
@ -31,12 +36,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/import`,
|
||||
path: `/:id/importBuys`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.import = async(ctx, id, options) => {
|
||||
Self.importBuys = async(ctx, id, options = {}) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const args = ctx.args;
|
||||
const models = Self.app.models;
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('importPreview', {
|
||||
description: '',
|
||||
Self.remoteMethod('importBuysPreview', {
|
||||
description: 'Calculates the preview buys for an entry import',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
|
@ -19,12 +19,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/importPreview`,
|
||||
path: `/:id/importBuysPreview`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.importPreview = async(id, buys) => {
|
||||
Self.importBuysPreview = async(id, buys) => {
|
||||
const models = Self.app.models;
|
||||
for (let buy of buys) {
|
||||
const packaging = await models.Packaging.findOne({
|
|
@ -59,7 +59,7 @@ describe('entry import()', () => {
|
|||
ref: 'Entry ref'
|
||||
}, options);
|
||||
|
||||
await app.models.Entry.import(ctx, newEntry.id, options);
|
||||
await app.models.Entry.importBuys(ctx, newEntry.id, options);
|
||||
|
||||
const updatedEntry = await app.models.Entry.findById(newEntry.id, null, options);
|
||||
const entryBuys = await app.models.Buy.find({
|
|
@ -0,0 +1,39 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('entry importBuysPreview()', () => {
|
||||
beforeAll(async done => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should import the buy rows', async() => {
|
||||
const buys = [
|
||||
{
|
||||
itemFk: 1,
|
||||
buyingValue: 5.77,
|
||||
description: 'Bow',
|
||||
grouping: 1,
|
||||
size: 1,
|
||||
volume: 1200
|
||||
},
|
||||
{
|
||||
itemFk: 4,
|
||||
buyingValue: 2.16,
|
||||
description: 'Arrow',
|
||||
grouping: 1,
|
||||
size: 25,
|
||||
volume: 1125
|
||||
}
|
||||
];
|
||||
|
||||
const result = await app.models.Entry.importBuysPreview(1, buys);
|
||||
const randomIndex = Math.floor(Math.random() * result.length);
|
||||
const buy = result[randomIndex];
|
||||
|
||||
expect(buy.packageFk).toEqual('3');
|
||||
});
|
||||
});
|
|
@ -2,6 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/entry/filter')(Self);
|
||||
require('../methods/entry/getEntry')(Self);
|
||||
require('../methods/entry/getBuys')(Self);
|
||||
require('../methods/entry/import')(Self);
|
||||
require('../methods/entry/importPreview')(Self);
|
||||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
};
|
||||
|
|
|
@ -55,7 +55,7 @@ class Controller extends Section {
|
|||
|
||||
fetchBuys(buys) {
|
||||
const params = {buys};
|
||||
const query = `Entries/${this.entry.id}/importPreview`;
|
||||
const query = `Entries/${this.entry.id}/importBuysPreview`;
|
||||
this.$http.get(query, {params}).then(res => {
|
||||
this.import.buys = res.data;
|
||||
});
|
||||
|
@ -63,7 +63,7 @@ class Controller extends Section {
|
|||
|
||||
onSubmit() {
|
||||
const params = this.import;
|
||||
const query = `Entries/${this.entry.id}/import`;
|
||||
const query = `Entries/${this.entry.id}/importBuys`;
|
||||
return this.$http.post(query, params)
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||
.then(() => this.$state.go('entry.card.buy.index'));
|
||||
|
|
Loading…
Reference in New Issue