Merge branch 'dev' into 5074-ticketBalance-null
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alexandre Riera 2023-01-30 14:01:17 +00:00
commit 5a72398393
3 changed files with 11 additions and 27 deletions

View File

@ -47,44 +47,32 @@ module.exports = function(Self) {
} }
try { try {
const promises = [];
if (args.deletes) { if (args.deletes) {
for (const itemTagId of args.deletes) { for (const itemTagId of args.deletes)
const itemTagDeleted = models.ItemTag.destroyById(itemTagId, myOptions); await models.ItemTag.destroyById(itemTagId, myOptions);
promises.push(itemTagDeleted);
}
} }
if (args.updates) { if (args.updates) {
for (const row of args.updates) { for (const row of args.updates) {
if (row.data.priority) { if (row.data.priority) {
const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions); const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions);
const itemTagUpdatedPriority = itemTag.updateAttributes({ await itemTag.updateAttributes({
priority: row.data.priority + args.maxPriority priority: row.data.priority + args.maxPriority
}, myOptions); }, myOptions);
promises.push(itemTagUpdatedPriority);
} }
} }
for (const row of args.updates) { for (const row of args.updates) {
const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions); const itemTag = await models.ItemTag.findById(row.where.id, null, myOptions);
const itemTagUpdated = itemTag.updateAttributes(row.data, myOptions); await itemTag.updateAttributes(row.data, myOptions);
promises.push(itemTagUpdated);
} }
} }
if (args.creates) { if (args.creates) {
for (const itemTag of args.creates) { for (const itemTag of args.creates)
const newItemTag = models.ItemTag.create(itemTag, myOptions); await models.ItemTag.create(itemTag, myOptions);
promises.push(newItemTag);
} }
}
const resolvedPromises = await Promise.all(promises);
if (tx) await tx.commit(); if (tx) await tx.commit();
return resolvedPromises;
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;

View File

@ -12,9 +12,8 @@ describe('tag onSubmit()', () => {
deletes: deletes deletes: deletes
} }
}; };
const result = await models.Tag.onSubmit(ctx, options); await models.Tag.onSubmit(ctx, options);
expect(result.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
@ -33,9 +32,8 @@ describe('tag onSubmit()', () => {
updates: updates updates: updates
} }
}; };
const result = await models.Tag.onSubmit(ctx, options); await models.Tag.onSubmit(ctx, options);
expect(result.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
@ -62,9 +60,8 @@ describe('tag onSubmit()', () => {
creates: creates creates: creates
} }
}; };
const result = await models.Tag.onSubmit(ctx, options); await models.Tag.onSubmit(ctx, options);
expect(result.length).toEqual(1);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
@ -88,9 +85,8 @@ describe('tag onSubmit()', () => {
} }
}; };
const result = await models.Tag.onSubmit(ctx, options); await models.Tag.onSubmit(ctx, options);
expect(result.length).toEqual(4);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();

View File

@ -24,7 +24,7 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
let statesList = await models.State.find({where: filter.where}, myOptions); let statesList = await models.State.find(filter, myOptions);
const isProduction = await models.Account.hasRole(userId, 'production', myOptions); const isProduction = await models.Account.hasRole(userId, 'production', myOptions);
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions); const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions);
const isAdministrative = await models.Account.hasRole(userId, 'administrative', myOptions); const isAdministrative = await models.Account.hasRole(userId, 'administrative', myOptions);