typing and comparison
This commit is contained in:
parent
dad54c97ed
commit
d7b92aedc1
6 changed files with 14 additions and 11 deletions
|
@ -4,7 +4,7 @@ export interface SynchronizeNewsletterDatesCommand {
|
|||
}
|
||||
|
||||
export interface NewsletterDateCommand {
|
||||
calendarId: number;
|
||||
calendarId: string;
|
||||
diffTitle?: string;
|
||||
diffDescription?: string;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<any> {
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue