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 {
|
export interface NewsletterDateCommand {
|
||||||
calendarId: number;
|
calendarId: string;
|
||||||
diffTitle?: string;
|
diffTitle?: string;
|
||||||
diffDescription?: string;
|
diffDescription?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,15 @@ export default abstract class NewsletterDatesCommandHandler {
|
||||||
return await dataSource.manager
|
return await dataSource.manager
|
||||||
.transaction(async (manager) => {
|
.transaction(async (manager) => {
|
||||||
let newDates = syncNewsletterDates.dates.filter(
|
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(
|
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) =>
|
let keptDates = syncNewsletterDates.dates.filter(
|
||||||
syncNewsletterDates.dates.map((np) => np.calendarId).includes(r.calendarId)
|
(r) =>
|
||||||
|
currentDates.some((cd) => cd.calendarId == r.calendarId) &&
|
||||||
|
!removeDates.some((cd) => cd.calendarId == r.calendarId)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newDates.length != 0) {
|
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 req {Request} Express req object
|
||||||
* @param res {Response} Express res object
|
* @param res {Response} Express res object
|
||||||
* @returns {Promise<*>}
|
* @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> {
|
export async function getNewsletterRecipientsById(req: Request, res: Response): Promise<any> {
|
||||||
let newsletterId = parseInt(req.params.newsletterId);
|
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" })
|
@PrimaryColumn({ type: "int" })
|
||||||
newsletterId: number;
|
newsletterId: number;
|
||||||
|
|
||||||
@PrimaryColumn({ type: "int" })
|
@PrimaryColumn({ type: "varchar" })
|
||||||
calendarId: number;
|
calendarId: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 255, nullable: true })
|
@Column({ type: "varchar", length: 255, nullable: true })
|
||||||
diffTitle: string | null;
|
diffTitle: string | null;
|
||||||
|
|
|
@ -13,6 +13,7 @@ export default abstract class NewsletterDatesService {
|
||||||
.getRepository(newsletterDates)
|
.getRepository(newsletterDates)
|
||||||
.createQueryBuilder("newsletterDates")
|
.createQueryBuilder("newsletterDates")
|
||||||
.leftJoinAndSelect("newsletterDates.calendar", "calendar")
|
.leftJoinAndSelect("newsletterDates.calendar", "calendar")
|
||||||
|
.leftJoinAndSelect("calendar.type", "type")
|
||||||
.leftJoinAndSelect("newsletterDates.newsletter", "newsletter")
|
.leftJoinAndSelect("newsletterDates.newsletter", "newsletter")
|
||||||
.where("newsletterDates.newsletterId = :id", { id: newsletterId })
|
.where("newsletterDates.newsletterId = :id", { id: newsletterId })
|
||||||
.getMany()
|
.getMany()
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { CalendarViewModel } from "./calendar.models";
|
||||||
|
|
||||||
export interface NewsletterDatesViewModel {
|
export interface NewsletterDatesViewModel {
|
||||||
newsletterId: number;
|
newsletterId: number;
|
||||||
calendarId: number;
|
calendarId: string;
|
||||||
diffTitle: string | null;
|
diffTitle: string | null;
|
||||||
diffDescription: string | null;
|
diffDescription: string | null;
|
||||||
calendar: CalendarViewModel;
|
calendar: CalendarViewModel;
|
||||||
|
|
Loading…
Reference in a new issue