chore: complete and fix bug in signature
This commit is contained in:
@@ -32,20 +32,12 @@ export class EmailSignaturesController {
|
||||
return this.emailSignaturesService.getBusinessSignature(business);
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
@Patch()
|
||||
@ApiOperation({ summary: "Update an email signature" })
|
||||
@ApiResponse({ status: 200, description: "Email signature updated successfully" })
|
||||
@ApiResponse({ status: 404, description: "Email signature not found" })
|
||||
update(@Param("id") id: string, @BusinessDec() business: Business, @Body() updateEmailSignatureDto: UpdateEmailSignatureDto) {
|
||||
return this.emailSignaturesService.update(id, business, updateEmailSignatureDto);
|
||||
}
|
||||
|
||||
@Patch(":id/toggle-active")
|
||||
@ApiOperation({ summary: "Activate an email signature" })
|
||||
@ApiResponse({ status: 200, description: "Email signature activated successfully" })
|
||||
@ApiResponse({ status: 404, description: "Email signature not found" })
|
||||
toggleActive(@Param("id") id: string, @BusinessDec() business: Business) {
|
||||
return this.emailSignaturesService.toggleActive(id, business);
|
||||
update(@BusinessDec() business: Business, @Body() updateEmailSignatureDto: UpdateEmailSignatureDto) {
|
||||
return this.emailSignaturesService.update(business, updateEmailSignatureDto);
|
||||
}
|
||||
|
||||
@Delete(":id")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Entity, EntityRepositoryType, Index, OneToOne, Opt, Property } from "@mikro-orm/core";
|
||||
import { Entity, EntityRepositoryType, Index, OneToOne, Property } from "@mikro-orm/core";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { Business } from "../../businesses/entities/business.entity";
|
||||
import { EmailSignatureRepository } from "../repositories/email-signature.repository";
|
||||
|
||||
@Entity({ repository: () => EmailSignatureRepository })
|
||||
@Index({ properties: ["business", "isActive"] })
|
||||
@Index({ properties: ["business"] })
|
||||
export class EmailSignature extends BaseEntity {
|
||||
@OneToOne(() => Business, (business) => business.emailSignature, { owner: true, deleteRule: "cascade" })
|
||||
business!: Business;
|
||||
@@ -16,8 +16,5 @@ export class EmailSignature extends BaseEntity {
|
||||
@Property({ type: "text", nullable: true })
|
||||
textContent?: string;
|
||||
|
||||
@Property({ type: "boolean", default: true })
|
||||
isActive!: boolean & Opt;
|
||||
|
||||
[EntityRepositoryType]?: EmailSignatureRepository;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ export class EmailSignatureRepository extends EntityRepository<EmailSignature> {
|
||||
return this.findOne({ business: { id: businessId } }, { orderBy: { createdAt: "DESC" } });
|
||||
}
|
||||
|
||||
async findActiveByBusinessId(businessId: string): Promise<EmailSignature[]> {
|
||||
return this.find({ business: { id: businessId }, isActive: true }, { orderBy: { createdAt: "DESC" } });
|
||||
}
|
||||
|
||||
async findByIdAndBusinessId(id: string, businessId: string): Promise<EmailSignature | null> {
|
||||
return this.findOne({ id, business: { id: businessId } });
|
||||
}
|
||||
|
||||
@@ -29,8 +29,10 @@ export class EmailSignaturesService {
|
||||
|
||||
//#########################
|
||||
|
||||
async update(id: string, business: Business, updateDto: UpdateEmailSignatureDto) {
|
||||
const { signature } = await this.findOne(id, business);
|
||||
async update(business: Business, updateDto: UpdateEmailSignatureDto) {
|
||||
const { signature } = await this.getBusinessSignature(business);
|
||||
|
||||
if (!signature) throw new BadRequestException(SignatureMessage.NOT_FOUND);
|
||||
|
||||
this.emailSignatureRepository.assign(signature, updateDto);
|
||||
await this.em.flush();
|
||||
@@ -43,19 +45,6 @@ export class EmailSignaturesService {
|
||||
await this.em.removeAndFlush(signature);
|
||||
return { message: SignatureMessage.DELETED };
|
||||
}
|
||||
//#########################
|
||||
|
||||
async toggleActive(id: string, business: Business) {
|
||||
const { signature } = await this.findOne(id, business);
|
||||
signature.isActive = !signature.isActive;
|
||||
|
||||
await this.em.flush();
|
||||
|
||||
return {
|
||||
message: SignatureMessage.TOGGLE_ACTIVE,
|
||||
signature,
|
||||
};
|
||||
}
|
||||
|
||||
//#########################
|
||||
async getBusinessSignature(business: Business) {
|
||||
|
||||
Reference in New Issue
Block a user