Skip to content

Commit

Permalink
Merge pull request #24 from Excali-Studio/exd-118
Browse files Browse the repository at this point in the history
EXD-118 - Random tag color generator
  • Loading branch information
coredumped7893 authored Aug 30, 2024
2 parents 52b56b5 + d8cd23d commit 29d0ab3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/canvas/canvas-tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/random-color-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const randomColorGenerator = () => {
const color = Math.floor(Math.random() * 16777215)
.toString(16)
.padStart(6, '0');
return `#${color}`;
};

0 comments on commit 29d0ab3

Please sign in to comment.