diff --git a/server/src/service/index.ts b/server/src/service/index.ts index 5db8afc4f..9bac381f6 100644 --- a/server/src/service/index.ts +++ b/server/src/service/index.ts @@ -18,6 +18,7 @@ export * from "@/service/infrastructure/emailService.js"; export * from "@/service/infrastructure/globalPingService.js"; export * from "@/service/infrastructure/networkService.js"; export * from "@/service/infrastructure/notificationsService.js"; +export * from "@/service/infrastructure/tagService.js"; export * from "@/service/infrastructure/statusService.js"; // Notification providers diff --git a/server/src/service/infrastructure/tagService.ts b/server/src/service/infrastructure/tagService.ts new file mode 100644 index 000000000..5dc6f7cef --- /dev/null +++ b/server/src/service/infrastructure/tagService.ts @@ -0,0 +1,37 @@ +import { Tag } from "@/types/index.js"; +import { ITagsRepository, IMonitorsRepository } from "@/repositories/index.js"; +export interface ITagsService { + createTag(tag: Partial, teamId: string): Promise; + getTag(tagId: string, teamId: string): Promise; + getTagsByTeamId(teamId: string): Promise; + updateTag(tagId: string, teamId: string, patch: Partial): Promise; + deleteTag(tagId: string, teamId: string): Promise; +} + +export class TagsService implements ITagsService { + constructor( + private tagsRepository: ITagsRepository, + private monitorsRepository: IMonitorsRepository + ) {} + + createTag = async (tagData: Partial, teamId: string): Promise => { + tagData.teamId = teamId; + return await this.tagsRepository.create(tagData); + }; + + getTag = async (tagId: string, teamId: string): Promise => { + return await this.tagsRepository.findById(tagId, teamId); + }; + + getTagsByTeamId = async (teamId: string): Promise => { + return await this.tagsRepository.findByTeamId(teamId); + }; + + updateTag = async (tagId: string, teamId: string, patch: Partial): Promise => { + return await this.tagsRepository.updateById(tagId, teamId, patch); + }; + deleteTag = async (tagId: string, teamId: string): Promise => { + await this.monitorsRepository.removeTagFromMonitors(tagId); + return await this.tagsRepository.deleteById(tagId, teamId); + }; +}