Commit d9aae7df authored by Jean-Philippe Steinmetz's avatar Jean-Philippe Steinmetz
Browse files

Fixing issue with building id query with version 0 specified.\nFixing issue...

Fixing issue with building id query with version 0 specified.\nFixing issue with updating a record and retrieving last edited version.
parent 9b094bc4
......@@ -93,7 +93,7 @@ class ModelUtils {
// e.g. WHERE idField1 = :idField1 OR idField2 = :idField2 ...
const where: any = [];
for (const prop of props) {
where.push(version ? { [prop]: id, version } : { [prop]: id });
where.push(version !== undefined ? { [prop]: id, version } : { [prop]: id });
}
return { where };
......@@ -118,7 +118,7 @@ class ModelUtils {
query.push({ [prop]: id });
}
if (version) {
if (version !== undefined) {
return { $and: [{ $or: query }, { version }] };
} else {
return { $or: query };
......
......@@ -653,7 +653,7 @@ abstract class ModelRoute<T extends BaseEntity | SimpleEntity> {
}
}
query = this.searchIdQuery(obj.uid, obj instanceof BaseEntity ? obj.version : undefined);
query = this.searchIdQuery(obj.uid, obj instanceof BaseEntity ? obj.version + 1 : undefined);
const result: T | undefined = await this.repo.findOne(query);
if (result) {
obj = new this.modelClass(result);
......
......@@ -61,6 +61,18 @@ describe("ModelUtils Tests", () => {
});
});
it("Can build id search query with single identifier and version 0.", () => {
const query: any = ModelUtils.buildIdSearchQueryMongo(SingleIdentifierClass, "MyID", 0);
expect(query).toEqual({
$and: [{
$or: [{ id: "MyID" }]
},
{
version: 0
}]
});
});
it("Can build id search query with multiple identifiers.", () => {
const query: any = ModelUtils.buildIdSearchQueryMongo(DoubleIdentifierClass, "MyID");
expect(query).toEqual({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment