skailan-conversations
Version:
Servicio de conversaciones y mensajería para Skailan
55 lines • 1.9 kB
JavaScript
import { Tag } from "../../../domain/entities/Tag";
export class TagPrismaRepository {
prisma;
constructor(prisma) {
this.prisma = prisma;
}
async findById(id) {
const tagData = await this.prisma.tag.findUnique({
where: { id },
});
if (!tagData) {
return null;
}
return new Tag(tagData.id, tagData.organizationId, tagData.name, tagData.createdAt, tagData.updatedAt);
}
async findByName(name, organizationId) {
const tagData = await this.prisma.tag.findFirst({
where: { name, organizationId },
});
if (!tagData) {
return null;
}
return new Tag(tagData.id, tagData.organizationId, tagData.name, tagData.createdAt, tagData.updatedAt);
}
async findAll(organizationId) {
const tagsData = await this.prisma.tag.findMany({
where: { organizationId },
});
return tagsData.map((tagData) => new Tag(tagData.id, tagData.organizationId, tagData.name, tagData.createdAt, tagData.updatedAt));
}
async save(tag) {
const savedTag = await this.prisma.tag.upsert({
where: { id: tag.id },
update: {
organizationId: tag.organizationId,
name: tag.name,
updatedAt: tag.updatedAt,
},
create: {
id: tag.id,
organizationId: tag.organizationId,
name: tag.name,
createdAt: tag.createdAt,
updatedAt: tag.updatedAt,
},
});
return new Tag(savedTag.id, savedTag.organizationId, savedTag.name, savedTag.createdAt, savedTag.updatedAt);
}
async delete(id, organizationId) {
await this.prisma.tag.delete({
where: { id },
});
}
}
//# sourceMappingURL=TagPrismaRepository.js.map