Skip to content

Commit

Permalink
Change regex for checkTraceName to let create trace, if another trace…
Browse files Browse the repository at this point in the history
… has parent string of this trace title

related #565
  • Loading branch information
mohammadranjbarz committed Jul 26, 2021
1 parent 2bd3a9e commit 580bfb1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/services/traces/checkTraceName.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const errors = require('@feathersjs/errors');
const logger = require('winston');

/**
* This function checks if traces name is unique in the campaign scope
Expand All @@ -16,14 +17,19 @@ const checkIfTraceNameIsUnique = () => async context => {
data.campaignId = trace.campaignId;
}
}
const query = {
_id: { $ne: context.id },
campaignId: data.campaignId,
title: new RegExp(`\\s*^${title.replace(/^\s+|\s+$|\s+(?=\s)/g, '')}\\s*`, 'i'),
};
const traceWithSameName = await traceService.find({
query: {
_id: { $ne: context.id },
campaignId: data.campaignId,
title: new RegExp(`\\s*${title.replace(/^\s+|\s+$|\s+(?=\s)/g, '')}\\s*`, 'i'),
},
query,
});
if (traceWithSameName.total > 0) {
logger.info('checkIfTraceNameIsUnique ', {
query,
traceWithSameName,
});
// trace titles are supposed to be unique
throw new errors.Forbidden(
'Trace title is repetitive. Please select a different title for the trace.',
Expand Down

0 comments on commit 580bfb1

Please sign in to comment.