add tag service
This commit is contained in:
1 parent
451c752170
commit
48735c7dc8
2 files changed
+38
No files matched your search
@@ -18,6 +18,7 @@ export * from "@/service/infrastructure/emailService.js";
|
|||||||
export * from "@/service/infrastructure/globalPingService.js";
|
export * from "@/service/infrastructure/globalPingService.js";
|
||||||
export * from "@/service/infrastructure/networkService.js";
|
export * from "@/service/infrastructure/networkService.js";
|
||||||
export * from "@/service/infrastructure/notificationsService.js";
|
export * from "@/service/infrastructure/notificationsService.js";
|
||||||
|
export * from "@/service/infrastructure/tagService.js";
|
||||||
export * from "@/service/infrastructure/statusService.js";
|
export * from "@/service/infrastructure/statusService.js";
|
||||||
|
|
||||||
// Notification providers
|
// Notification providers
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { Tag } from "@/types/index.js";
|
||||||
|
import { ITagsRepository, IMonitorsRepository } from "@/repositories/index.js";
|
||||||
|
export interface ITagsService {
|
||||||
|
createTag(tag: Partial<Tag>, teamId: string): Promise<Tag>;
|
||||||
|
getTag(tagId: string, teamId: string): Promise<Tag>;
|
||||||
|
getTagsByTeamId(teamId: string): Promise<Tag[]>;
|
||||||
|
updateTag(tagId: string, teamId: string, patch: Partial<Tag>): Promise<Tag>;
|
||||||
|
deleteTag(tagId: string, teamId: string): Promise<Tag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TagsService implements ITagsService {
|
||||||
|
constructor(
|
||||||
|
private tagsRepository: ITagsRepository,
|
||||||
|
private monitorsRepository: IMonitorsRepository
|
||||||
|
) {}
|
||||||
|
|
||||||
|
createTag = async (tagData: Partial<Tag>, teamId: string): Promise<Tag> => {
|
||||||
|
tagData.teamId = teamId;
|
||||||
|
return await this.tagsRepository.create(tagData);
|
||||||
|
};
|
||||||
|
|
||||||
|
getTag = async (tagId: string, teamId: string): Promise<Tag> => {
|
||||||
|
return await this.tagsRepository.findById(tagId, teamId);
|
||||||
|
};
|
||||||
|
|
||||||
|
getTagsByTeamId = async (teamId: string): Promise<Tag[]> => {
|
||||||
|
return await this.tagsRepository.findByTeamId(teamId);
|
||||||
|
};
|
||||||
|
|
||||||
|
updateTag = async (tagId: string, teamId: string, patch: Partial<Tag>): Promise<Tag> => {
|
||||||
|
return await this.tagsRepository.updateById(tagId, teamId, patch);
|
||||||
|
};
|
||||||
|
deleteTag = async (tagId: string, teamId: string): Promise<Tag> => {
|
||||||
|
await this.monitorsRepository.removeTagFromMonitors(tagId);
|
||||||
|
return await this.tagsRepository.deleteById(tagId, teamId);
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user