diff --git a/src/command/newsletterDatesCommand.ts b/src/command/newsletterDatesCommand.ts index 70d789f..5b92ba6 100644 --- a/src/command/newsletterDatesCommand.ts +++ b/src/command/newsletterDatesCommand.ts @@ -4,7 +4,7 @@ export interface SynchronizeNewsletterDatesCommand { } export interface NewsletterDateCommand { - calendarId: number; + calendarId: string; diffTitle?: string; diffDescription?: string; } diff --git a/src/command/newsletterDatesCommandHandler.ts b/src/command/newsletterDatesCommandHandler.ts index f1ec22b..99ee1ad 100644 --- a/src/command/newsletterDatesCommandHandler.ts +++ b/src/command/newsletterDatesCommandHandler.ts @@ -17,13 +17,15 @@ export default abstract class NewsletterDatesCommandHandler { return await dataSource.manager .transaction(async (manager) => { let newDates = syncNewsletterDates.dates.filter( - (r) => !currentDates.map((np) => np.calendarId).includes(r.calendarId) + (r) => !currentDates.some((cd) => cd.calendarId == r.calendarId) ); let removeDates = currentDates.filter( - (r) => !syncNewsletterDates.dates.map((np) => np.calendarId).includes(r.calendarId) + (r) => !syncNewsletterDates.dates.some((cd) => cd.calendarId == r.calendarId) ); - let keptDates = currentDates.filter((r) => - syncNewsletterDates.dates.map((np) => np.calendarId).includes(r.calendarId) + let keptDates = syncNewsletterDates.dates.filter( + (r) => + currentDates.some((cd) => cd.calendarId == r.calendarId) && + !removeDates.some((cd) => cd.calendarId == r.calendarId) ); if (newDates.length != 0) { diff --git a/src/controller/admin/newsletterController.ts b/src/controller/admin/newsletterController.ts index 620687f..0e141f5 100644 --- a/src/controller/admin/newsletterController.ts +++ b/src/controller/admin/newsletterController.ts @@ -62,7 +62,7 @@ export async function getNewsletterDatesById(req: Request, res: Response): Promi } /** - * @description get newsletter recipientss by id + * @description get newsletter recipients by id * @param req {Request} Express req object * @param res {Response} Express res object * @returns {Promise<*>} @@ -70,9 +70,9 @@ export async function getNewsletterDatesById(req: Request, res: Response): Promi export async function getNewsletterRecipientsById(req: Request, res: Response): Promise { let newsletterId = parseInt(req.params.newsletterId); - let recipientss = await NewsletterRecipientsService.getAll(newsletterId); + let recipients = await NewsletterRecipientsService.getAll(newsletterId); - res.json(NewsletterRecipientsFactory.mapToBase(recipientss)); + res.json(NewsletterRecipientsFactory.mapToBase(recipients)); } /** diff --git a/src/entity/newsletterDates.ts b/src/entity/newsletterDates.ts index 5ef80ba..aefb8ee 100644 --- a/src/entity/newsletterDates.ts +++ b/src/entity/newsletterDates.ts @@ -7,8 +7,8 @@ export class newsletterDates { @PrimaryColumn({ type: "int" }) newsletterId: number; - @PrimaryColumn({ type: "int" }) - calendarId: number; + @PrimaryColumn({ type: "varchar" }) + calendarId: string; @Column({ type: "varchar", length: 255, nullable: true }) diffTitle: string | null; diff --git a/src/service/newsletterDatesService.ts b/src/service/newsletterDatesService.ts index 5152de0..08c4b0e 100644 --- a/src/service/newsletterDatesService.ts +++ b/src/service/newsletterDatesService.ts @@ -13,6 +13,7 @@ export default abstract class NewsletterDatesService { .getRepository(newsletterDates) .createQueryBuilder("newsletterDates") .leftJoinAndSelect("newsletterDates.calendar", "calendar") + .leftJoinAndSelect("calendar.type", "type") .leftJoinAndSelect("newsletterDates.newsletter", "newsletter") .where("newsletterDates.newsletterId = :id", { id: newsletterId }) .getMany() diff --git a/src/viewmodel/admin/newsletterDates.models.ts b/src/viewmodel/admin/newsletterDates.models.ts index a1bf0cc..074056d 100644 --- a/src/viewmodel/admin/newsletterDates.models.ts +++ b/src/viewmodel/admin/newsletterDates.models.ts @@ -2,7 +2,7 @@ import { CalendarViewModel } from "./calendar.models"; export interface NewsletterDatesViewModel { newsletterId: number; - calendarId: number; + calendarId: string; diffTitle: string | null; diffDescription: string | null; calendar: CalendarViewModel;