Skip to content

Commit

Permalink
enhancing some features
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Dec 9, 2024
1 parent 640b3e8 commit c2808a6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ temp.json
.vscode

# db
1733732167717-new.ts
13 changes: 9 additions & 4 deletions src/features/analytic/analytic.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
NeedTypeEnum,
SAYPlatformRoles,
} from 'src/types/interfaces/interface';
import { convertFlaskToSayRoles } from 'src/utils/helpers';
import { convertFlaskToSayRoles, daysDifference } from 'src/utils/helpers';
import { UserService } from '../user/user.service';
import { AnalyticService } from './analytic.service';
import config from 'src/config';
Expand All @@ -30,7 +30,7 @@ export class AnalyticController {
private userService: UserService,

private readonly analyticService: AnalyticService,
) { }
) {}

@Get('ecosystem/children')
@ApiOperation({ description: 'get SAY children ecosystem analytics' })
Expand Down Expand Up @@ -60,8 +60,11 @@ export class AnalyticController {
meanFamilyMembers: number;
childrenList: any;
};
result = config().dataCache.fetchChildrenEcosystem();
if (!result) {
const data = config().dataCache.fetchChildrenEcosystem();
console.log('datafff');
console.log(data);

if (!data || daysDifference(data.created, new Date()) > 1) {
result = await this.analyticService.getChildrenEcosystemAnalytic();
config().dataCache.storeChildrenEcosystem({
meanNeedsPerChild: result.meanNeedsPerChild,
Expand All @@ -79,6 +82,8 @@ export class AnalyticController {
meanFamilyMembers: result.meanFamilyMembers,
childrenList: result.childrenList,
});
} else {
result = data;
}

return result;
Expand Down
16 changes: 14 additions & 2 deletions src/features/need/need.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Get,
Param,
Post,
Query,
Req,
} from '@nestjs/common';
import { ApiHeader, ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
Expand Down Expand Up @@ -157,6 +158,17 @@ export class NeedController {
return await this.needService.getNestPurchaserNeeds(flaskUserId);
}

@Get('title/search') // this will replace need template / preNeed
@ApiOperation({ description: 'Get a need from db 2 by title' })
async getFlaskNeedByTitle(@Req() req: Request, @Query('q') query: string) {
const panelFlaskUserId = req.headers['panelFlaskUserId'];
const panelFlaskTypeId = req.headers['panelFlaskTypeId'];
if (!isAuthenticated(panelFlaskUserId, panelFlaskTypeId)) {
throw new ForbiddenException(401, 'You Are not authorized!');
}
return await this.needService.getNeedByTitle(query);
}

@Get(`flask/:id`)
@ApiOperation({ description: 'Get a need from db 2' })
async getFlaskNeed(@Req() req: Request, @Param('id') id: number) {
Expand All @@ -176,12 +188,12 @@ export class NeedController {
) {
const panelFlaskUserId = req.headers['panelFlaskUserId'];
const panelFlaskTypeId = req.headers['panelFlaskTypeId'];

if (!isAuthenticated(panelFlaskUserId, panelFlaskTypeId)) {
throw new ForbiddenException(401, 'You Are not authorized!');
}

const theNeed = await this.needService.getNeedByFlaskId(needFlaskId)
const theNeed = await this.needService.getNeedByFlaskId(needFlaskId);

return theNeed;
}
Expand Down
29 changes: 29 additions & 0 deletions src/features/need/need.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,35 @@ export class NeedService {
return user;
}

async getNeedByTitle(title: string): Promise<Need[]> {
console.log(title);
return await this.flaskNeedRepository
.createQueryBuilder('need')
.select()
.where(
new Brackets((qb) => {
qb.where('need.type = :typeProduct', {
typeProduct: NeedTypeEnum.PRODUCT,
})
.andWhere('need.title ILIKE :searchTerm', {
searchTerm: `%${title}%`,
})
.orWhere('need.type = :typeService', {
typeService: NeedTypeEnum.SERVICE,
})
.andWhere(
"need.name_translations -> 'fa' ILIKE :nameTranslations",
{
nameTranslations: `%${title}%`,
},
);
}),
)
.andWhere('need.isDeleted = :needDeleted', { needDeleted: false })
.andWhere('need.isConfirmed = :needConfirmed', { needConfirmed: true })
.getMany();
}

async updateNeedRatios(
need: NeedEntity,
distanceRatio: Decimal,
Expand Down
7 changes: 4 additions & 3 deletions src/features/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export class ScheduleService {
this.rolesCount();
}

@Cron(CronExpression.EVERY_1ST_DAY_OF_MONTH_AT_MIDNIGHT, {

@Cron(CronExpression.EVERY_WEEK, {
name: 'ActiveFamilies',
timeZone: 'Asia/Tehran',
})
Expand Down Expand Up @@ -129,7 +130,7 @@ export class ScheduleService {
}

// ERROR [Scheduler] ServerError: Can't send mail - all recipients were rejected: 550 <[email protected]> No such user here
@Cron('00 09 * * Sun', {
@Cron('30 09 * * Mon', {
name: 'MonthlyCampaigns try At 09:00 on Sunday.', // we try every week and only send to those who did not receive (because their child have no needs, etc.)
timeZone: 'Asia/Tehran',
})
Expand All @@ -146,7 +147,7 @@ export class ScheduleService {
this.logger.debug(
'Sending user Campaigns at 01:00 PM, only on Thursdays',
);
// await this.campaignService.sendUserMonthlyCampaigns();
await this.campaignService.sendUserMonthlyCampaigns();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export async function updateFlaskCacheAuthentication(req, logger: Logger) {
accessToken,
Number(requestPanelFlaskId),
);
console.log('here2');

if (!socialWorker) {
throw new ForbiddenException('You Do not have Access!');
Expand Down
28 changes: 14 additions & 14 deletions src/utils/dataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,46 +157,46 @@ export default class DataCache {
};

expirePanelAccessToken = (flaskSwId: number) =>
(this.authentication[String(flaskSwId)] = {
...this.authentication[String(flaskSwId)],
isExpired: true,
});
(this.authentication[String(flaskSwId)] = {
...this.authentication[String(flaskSwId)],
isExpired: true,
});
expireDappAccessToken = (flaskFamilyId: number) =>
(this.authentication[String(flaskFamilyId)] = {
...this.authentication[String(flaskFamilyId)],
isExpired: true,
});
(this.authentication[String(flaskFamilyId)] = {
...this.authentication[String(flaskFamilyId)],
isExpired: true,
});

// panel analytic scatter chart
roleScatteredData() {
return {
father: getScattered(
this.familyData.fathersData,
this.familyData && this.familyData.fathersData,
VirtualFamilyRole.FATHER,
this.medianList,
),
mother: getScattered(
this.familyData.mothersData,
this.familyData && this.familyData.mothersData,
VirtualFamilyRole.MOTHER,
this.medianList,
),
amoo: getScattered(
this.familyData.amoosData,
this.familyData && this.familyData.amoosData,
VirtualFamilyRole.AMOO,
this.medianList,
),
khaleh: getScattered(
this.familyData.khalehsData,
this.familyData && this.familyData.khalehsData,
VirtualFamilyRole.KHALEH,
this.medianList,
),
daei: getScattered(
this.familyData.daeisData,
this.familyData && this.familyData.daeisData,
VirtualFamilyRole.DAEI,
this.medianList,
),
amme: getScattered(
this.familyData.ammesData,
this.familyData && this.familyData.ammesData,
VirtualFamilyRole.AMME,
this.medianList,
),
Expand Down

0 comments on commit c2808a6

Please sign in to comment.