Skip to content

Commit

Permalink
Merge pull request #566 from Giveth/f_565_change_check_trace_name_regex
Browse files Browse the repository at this point in the history
Change regex for checkTraceName
  • Loading branch information
aminlatifi authored Jul 27, 2021
2 parents 2bd3a9e + adacad1 commit b163fa9
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 b163fa9

Please sign in to comment.