Allow Delete tag with transactions
MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -157,17 +157,6 @@ export default class TagService {
action: action
});
}
- // Has transactions
- if (tag.transactionsCount > 0) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.TAG_HAS_TRANSACTIONS,
- message: `Cannot delete Tag ID '${tag.id}' which has '${tag.transactionsCount}' transaction(s)`,
- module: MODULE_NAME, method: 'handleDeleteTag',
- user: req.user,
- action: action
- });
- }
// Delete the Tag
await TagStorage.deleteTag(req.user.tenantID, tag.id);
// Check if default deleted?
@@ -254,7 +243,7 @@ export default class TagService {
if (transactions.count > 0) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.TAG_ALREADY_EXIST_ERROR,
+ errorCode: HTTPError.TAG_HAS_TRANSACTIONS,
message: `Tag with ID '${filteredRequest.id}' has been used in previous transactions`,
module: MODULE_NAME, method: 'handleCreateTag',
user: req.user,
@@ -731,16 +720,6 @@ export default class TagService {
action: action,
detailedMessages: { tag }
});
- } else if (tag.transactionsCount > 0) {
- result.inError++;
- await Logging.logError({
- tenantID: loggedUser.tenantID,
- user: loggedUser,
- module: MODULE_NAME, method: 'handleDeleteTags',
- message: `Cannot delete Tag ID '${tag.id}' which has '${tag.transactionsCount}' transaction(s)`,
- action: action,
- detailedMessages: { tag }
- });
} else {
// Delete the Tag
await TagStorage.deleteTag(loggedUser.tenantID, tag.id);

MODIFY
test/api/UserTest.ts
test/api/UserTest.ts
@@ -172,21 +172,6 @@ describe('User tests', function() {
testData.createdTags.push(testData.newTag);
});
- it('Should not be able to delete a badge that has already been used', async () => {
- const connectorId = 1;
- const tagId = testData.newTag.id;
- const meterStart = 180;
- const startDate = moment();
- const response = await testData.chargingStationContext.startTransaction(
- connectorId, tagId, meterStart, startDate.toDate());
- // eslint-disable-next-line @typescript-eslint/unbound-method
- expect(response).to.be.transactionValid;
- const resDelete = await testData.userService.userApi.deleteTag(tagId);
- expect(resDelete.status).to.equal(HTTPError.TAG_HAS_TRANSACTIONS);
- const tag = (await testData.userService.userApi.readTag(tagId)).data;
- expect(tag).to.not.be.null;
- });
-
it('Should be able to deactivate a badge', async () => {
testData.newTag.active = false;
const response = await testData.userService.userApi.updateTag(testData.newTag);

Allow Delete tag with transactions