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,26 +22,10 @@ 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) {
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
@ -54,5 +38,6 @@ module.exports = Self => {
} 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);
});
});
});