diff --git a/src/canvas/canvas-tag.service.ts b/src/canvas/canvas-tag.service.ts index 111def2..2eaefdd 100644 --- a/src/canvas/canvas-tag.service.ts +++ b/src/canvas/canvas-tag.service.ts @@ -13,6 +13,7 @@ import { PagedResult, } from '../common/pageable.utils'; import { Uuid } from '../common/common.interface'; +import { randomColorGenerator } from '../helpers/random-color-generator'; @Injectable() export class CanvasTagService { @@ -34,7 +35,7 @@ export class CanvasTagService { const tag = new CanvasTagEntity(); tag.name = tagName; tag.description = command.description?.trim(); - tag.color = command.color?.trim(); + tag.color = command.color?.trim() || randomColorGenerator().trim(); await this.canvasTagRepository.save(tag); return tag; } diff --git a/src/helpers/random-color-generator.ts b/src/helpers/random-color-generator.ts new file mode 100644 index 0000000..cf2c5ab --- /dev/null +++ b/src/helpers/random-color-generator.ts @@ -0,0 +1,6 @@ +export const randomColorGenerator = () => { + const color = Math.floor(Math.random() * 16777215) + .toString(16) + .padStart(6, '0'); + return `#${color}`; +};