Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ff-*): reported issues #504

Merged
merged 4 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions services/flight-crawler/src/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function crawlAllJobs(): Promise<void> {
const oldResultList = job.resultList;
const resultList = await crawl(job.detail);
job.resultList = resultList;
if (job.resultList.length > 0 && differentObject(job.resultList, oldResultList)) {
if (differentObject(job.resultList, oldResultList)) {
const message = makeMessage(job);
await notify(config.notifier.to, message);
logger.logOther(`Notified to ${config.notifier.to}!`);
Expand Down Expand Up @@ -57,7 +57,7 @@ function makeRequestOption(detail: JobDetail): Partial<FetchOptions> & {url: str
pageSize: 20,
pageNumber: 0,
originAirportIataCode: detail.origin,
destinationAirportIataCode: detail.dest,
destinationAirportIataCode: detail.destination,
departureDate: detail.date,
sort: 1,
},
Expand Down Expand Up @@ -135,16 +135,27 @@ function extraFilterResult(jobResultList: Array<JobResult>, detail: JobDetail):
function makeMessage(job: Job): string {
logger.logMethod('makeMessage');

let message = `پرواز از ${cityList[job.detail.origin]} به ${cityList[job.detail.dest]} در تاریخ ${job.detail.date}`;
// prettier-ignore
const resultListStr = job.resultList.length === 0 ? 'هیچ پروازی یافت نشد!'
: job.resultList.map((jobResult) => `
قیمت: ${jobResult.price}
ساعت: ${jobResult.time}
هواپیمایی ${jobResult.airline}
`).join('');

// add description if exists
job.detail.description ? (message += '\nتوضیحات:' + job.detail.description) : null;
return `
تغییرات جدید در جستجوی ${job.id}:

job.resultList.forEach((jobResult) => {
message += '\n\n' + `قیمت: ${jobResult.price}\n ساعت: ${jobResult.time}\nتعداد صندلی: ${jobResult.seatCount}`;
});
${job.detail.description}

${cityList[job.detail.origin]} ✈️ ${cityList[job.detail.destination]}

تاریخ: ${job.detail.date}
حداکثر قیمت: ${job.detail.maxPrice}
تعداد صندلی: ${job.detail.seatCount}

return message;
${resultListStr}
`.replaceAll(' ', '');
}

async function notify(to: string, message: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion services/flight-crawler/src/lib/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Job extends AlwatrDocumentObject {

export interface JobDetail extends Record<string, unknown> {
origin: string;
dest: string;
destination: string;
date: string;
seatCount: number;
maxPrice: number | null;
Expand Down
9 changes: 7 additions & 2 deletions services/telegram-notifier/src/bot/command/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bot.command('start', async (ctx): Promise<void> => {
logger.logMethodArgs('command/start', {chatId, token});

if (token == null) {
ctx.reply('You don\'t have permission!');
ctx.reply('این یک بات خصوصی هستش! لطفا مزاحم نشوید.');
return;
}

Expand All @@ -18,8 +18,13 @@ bot.command('start', async (ctx): Promise<void> => {
memberList: [],
};

if (target.memberList.indexOf(chatId) !== -1) {
ctx.reply('شما درحال حاضر عضو این لیست هستید!');
return;
}

target.memberList.push(chatId);
storage.set(target, true);

await ctx.reply('You are registered to notify list!');
await ctx.reply('شما با موفقیت در لیست ثبت شدید.');
});
2 changes: 1 addition & 1 deletion uniquely/flight-finder-pwa/src/component/job-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class JobItem extends AlwatrElement {
<ion-item-sliding>
<ion-item class="job" lines="full">
<ion-label>
${this.__renderTitle(i18nCityList[this.job.detail.origin], i18nCityList[this.job.detail.dest])}
${this.__renderTitle(i18nCityList[this.job.detail.origin], i18nCityList[this.job.detail.destination])}
${this.__renderSubtitle(
this.job.detail.date,
this.job.detail.dayPart.map((part) => i18nDayPartList[part]).join(' - '),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class PageFlightFinder extends AlwatrElement {

PageFlightFinder.jobAddSignal.dispatch({
detail: {
dest: this.__newJob.dest as string,
destination: this.__newJob.destination as string,
origin: this.__newJob.origin as string,
dayPart: (this.__newJob.dayPart as dayParts[]) ?? [],
maxPrice: this.__newJob.maxPrice ?? null,
Expand Down
2 changes: 1 addition & 1 deletion uniquely/flight-finder-pwa/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Job extends AlwatrDocumentObject {

export interface JobDetail {
origin: string;
dest: string;
destination: string;
date: string;
seatCount: number;
maxPrice: number | null;
Expand Down