refs #5063 deleted item checked in image, added front test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-02-24 10:25:08 +01:00
parent 271a6d898d
commit afb14044cc
4 changed files with 29 additions and 26 deletions

View File

@ -140,7 +140,6 @@ module.exports = Self => {
const item = await model.findById(entityId, null, myOptions);
if (item) {
if (collection.model == 'Item') fileName += '#';
await item.updateAttribute(
collection.property,
fileName,

View File

@ -22,37 +22,22 @@ module.exports = Self => {
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) await Self.availableId(ctx);
else {
const changes = ctx.data || ctx.instance;
const orgData = ctx.currentInstance;
const hasChanges = orgData && changes;
const image = changes.image || orgData.image;
const imageChanged = hasChanges && orgData.image != image;
if (imageChanged) {
try {
changes.image = changes.image.slice(0, -1);
if (orgData.isPhotoRequested == true) changes.isPhotoRequested = false;
} catch (e) {
throw new UserError(e);
}
}
}
});
Self.availableId = async function(ctx) {
try {
let query = `SELECT i1.id + 1 as id FROM vn.item i1
if (ctx.isNewInstance) {
try {
let query = `SELECT i1.id + 1 as id FROM vn.item i1
LEFT JOIN vn.item i2 ON i1.id + 1 = i2.id
WHERE i2.id IS NULL ORDER BY i1.id LIMIT 1`;
let newId = await Self.rawSql(query);
let newId = await Self.rawSql(query);
ctx.instance.id = newId[0].id;
return ctx.instance.id;
} catch (e) {
throw new UserError(e);
ctx.instance.id = newId[0].id;
return ctx.instance.id;
} catch (e) {
throw new UserError(e);
}
}
};
};

View File

@ -91,6 +91,11 @@ class Controller extends Descriptor {
this.$.photo.setAttribute('src', newSrc);
this.$.photo.setAttribute('zoom-image', newZoomSrc);
if (this.item.isPhotoRequested) {
this.$http.patch(`Items/${this.item.id}`, {isPhotoRequested: false})
.then(() => this.item.isPhotoRequested = false);
}
}
getWarehouseName(warehouseFk) {

View File

@ -8,7 +8,8 @@ describe('vnItemDescriptor', () => {
id: 1,
itemType: {
warehouseFk: 1
}
},
isPhotoRequested: true
};
const stock = {
visible: 1,
@ -43,4 +44,17 @@ describe('vnItemDescriptor', () => {
expect(controller.item).toEqual(item);
});
});
describe('onUploadResponse()', () => {
it(`should change isPhotoRequested when a new photo is uploaded`, () => {
$httpBackend.expectPATCH(`Items/${item.id}`).respond();
controller.$rootScope = {imagePath: () => {}};
controller.$.photo = {setAttribute: () => {}};
controller.item = item;
controller.onUploadResponse();
$httpBackend.flush();
expect(controller.item.isPhotoRequested).toEqual(false);
});
});
});