Skip to content

Commit

Permalink
mail servide and more
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 7, 2023
1 parent 383bf0f commit b33f639
Show file tree
Hide file tree
Showing 48 changed files with 2,836 additions and 5,974 deletions.
2 changes: 1 addition & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceRoot": "src",
"compilerOptions": {
"assets": [
"features/mail/templates/**/*"
"features/campaign/templates/**/*"
],
"watchAssets": true
}
Expand Down
5 changes: 3 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { MineModule } from './features/mine/mine.module';
import { ContributionModule } from './features/contribution/contribution.module';
import { ThrottlerModule } from '@nestjs/throttler';
import { postgresDataSourceOptions } from './db/data-source';
import { MailModule } from './features/mail/mail.module';
import { CampaignModule } from './features/campaign/campaign.module';
import { Countries } from './entities/flaskEntities/countries.entity';

const imports = [
Expand Down Expand Up @@ -80,7 +80,7 @@ const imports = [
// ServeStaticModule.forRoot({
// rootPath: join(__dirname, '..', 'files'),
// }),
MailModule,
CampaignModule,
ScheduleTaskModule,
GatewayModule,
LocationModule,
Expand All @@ -105,6 +105,7 @@ const imports = [
CommentModule,
MineModule,
ContributionModule,
CampaignModule,
];

@Module({
Expand Down
14 changes: 0 additions & 14 deletions src/db/migrations/1698779896533-new.ts

This file was deleted.

44 changes: 0 additions & 44 deletions src/db/migrations/1699105112698-new.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/db/migrations/1699180499824-new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class New1699180499824 implements MigrationInterface {
name = 'New1699180499824'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME COLUMN "campaign" TO "campaignName"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME COLUMN "campaignName" TO "campaign"`);
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class New1699105844419 implements MigrationInterface {
name = 'New1699105844419'
export class New1699181005168 implements MigrationInterface {
name = 'New1699181005168'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD "campaignNumber" integer NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD CONSTRAINT "UQ_77f8819f4ce0b24cffce96c2906" UNIQUE ("campaignNumber")`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP COLUMN "campaignName"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD "campaignName" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "all_user_entity" ALTER COLUMN "monthlyEmail" SET DEFAULT true`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP CONSTRAINT "UQ_77f8819f4ce0b24cffce96c2906"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP COLUMN "campaignNumber"`);
await queryRunner.query(`ALTER TABLE "all_user_entity" ALTER COLUMN "monthlyEmail" SET DEFAULT false`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP COLUMN "campaignName"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD "campaignName" integer NOT NULL`);
}

}
24 changes: 24 additions & 0 deletions src/db/migrations/1699181702531-new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class New1699181702531 implements MigrationInterface {
name = 'New1699181702531'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME COLUMN "campaignNumber" TO "campaignCode"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME CONSTRAINT "UQ_77f8819f4ce0b24cffce96c2906" TO "UQ_b9e68834e43af5477e94c2796ae"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP CONSTRAINT "UQ_b9e68834e43af5477e94c2796ae"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP COLUMN "campaignCode"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD "campaignCode" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD CONSTRAINT "UQ_b9e68834e43af5477e94c2796ae" UNIQUE ("campaignCode")`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP CONSTRAINT "UQ_b9e68834e43af5477e94c2796ae"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" DROP COLUMN "campaignCode"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD "campaignCode" integer NOT NULL`);
await queryRunner.query(`ALTER TABLE "campaign_entity" ADD CONSTRAINT "UQ_b9e68834e43af5477e94c2796ae" UNIQUE ("campaignCode")`);
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME CONSTRAINT "UQ_b9e68834e43af5477e94c2796ae" TO "UQ_77f8819f4ce0b24cffce96c2906"`);
await queryRunner.query(`ALTER TABLE "campaign_entity" RENAME COLUMN "campaignCode" TO "campaignNumber"`);
}

}
21 changes: 6 additions & 15 deletions src/entities/campaign.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Entity, Column, ManyToOne, ManyToMany, JoinTable } from 'typeorm';
import { BaseEntity } from './BaseEntity';
import { AllUserEntity } from './user.entity';
import { CampaignEnum, CampaignTypeEnum } from 'src/types/interfaces/interface';
import {
CampaignNameEnum,
CampaignTypeEnum,
} from 'src/types/interfaces/interface';
import { SignatureEntity } from './signature.entity';
import { NeedEntity } from './need.entity';

Expand All @@ -11,29 +14,17 @@ export class CampaignEntity extends BaseEntity {
title: string;

@Column({ nullable: false })
campaign: CampaignEnum;
campaignName: CampaignNameEnum;

@Column({ nullable: false })
type: CampaignTypeEnum;

@Column({ nullable: false, unique: true })
campaignNumber: number;
campaignCode: string;

@ManyToMany(() => AllUserEntity, (u) => u.campaigns, {
eager: true,
})
@JoinTable()
receivers: AllUserEntity[];

@ManyToMany(() => SignatureEntity, (s) => s.campaigns, {
eager: true,
})
@JoinTable()
contentSignatures?: SignatureEntity[];

@ManyToMany(() => NeedEntity, (n) => n.campaigns, {
eager: true,
})
@JoinTable()
contentNeeds?: NeedEntity[];
}
3 changes: 3 additions & 0 deletions src/entities/flaskEntities/receipt.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class Receipt extends BaseEntity {
@Column()
description: string;

@Column({ nullable: true })
is_public: boolean;

@Column({ nullable: true })
deleted: Date;
}
3 changes: 0 additions & 3 deletions src/entities/need.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,4 @@ export class NeedEntity extends BaseEntity {

@OneToMany(() => VariableEntity, (v) => v.need, { eager: true })
variables?: VariableEntity[];

@ManyToMany(() => CampaignEntity, (c) => c.contentNeeds)
campaigns: CampaignEntity[];
}
3 changes: 0 additions & 3 deletions src/entities/signature.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ export class SignatureEntity extends BaseEntity {
nullable: false,
})
need: NeedEntity;

@ManyToMany(() => CampaignEntity, (c) => c.contentNeeds)
campaigns: CampaignEntity[];
}
4 changes: 2 additions & 2 deletions src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AllUserEntity extends BaseEntity {
})
comments: CommentEntity[];

@ManyToMany(() => CampaignEntity, (c) => c.contentNeeds)
@ManyToMany(() => CampaignEntity, (c) => c.receivers)
campaigns: CampaignEntity[];

@Column({ nullable: false })
Expand Down Expand Up @@ -65,7 +65,7 @@ export class AllUserEntity extends BaseEntity {
})
signatures: SignatureEntity[];

@Column({ default: false })
@Column({ default: true })
monthlyEmail: boolean;

@OneToMany(() => CampaignEntity, (e) => e.receivers, {
Expand Down
15 changes: 14 additions & 1 deletion src/features/analytic/analytic.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ import { AnalyticMiddleware } from './middlewares/analytic.middleware';
import { PaymentEntity } from 'src/entities/payment.entity';
import { VariableEntity } from 'src/entities/variable.entity';
import { ChildrenPreRegisterEntity } from 'src/entities/childrenPreRegister.entity';
import { Receipt } from 'src/entities/flaskEntities/receipt.entity';
import { NeedReceipt } from 'src/entities/flaskEntities/needReceipt.entity';

@Module({
imports: [
TypeOrmModule.forFeature(
[User, SocialWorker, Need, Child, NGO, Payment, Family, UserFamily],
[
User,
SocialWorker,
Need,
Child,
NGO,
Payment,
Family,
UserFamily,
Receipt,
NeedReceipt,
],
'flaskPostgres',
),
TypeOrmModule.forFeature([
Expand Down
16 changes: 10 additions & 6 deletions src/features/analytic/analytic.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { mean, round } from 'mathjs';
import config from 'src/config';
import { Child } from 'src/entities/flaskEntities/child.entity';
import { Family } from 'src/entities/flaskEntities/family.entity';
import { Need } from 'src/entities/flaskEntities/need.entity';
Expand All @@ -16,7 +17,7 @@ import {
import {
daysDifference,
getNeedsTimeLine,
removeDuplicates,
removeSpecialDuplicates,
timeDifferenceWithComment,
} from 'src/utils/helpers';
import { Repository } from 'typeorm';
Expand Down Expand Up @@ -203,6 +204,7 @@ export class AnalyticService {
.getCount();

return {
noNeeds: config().dataCache.fetchChildrenNoNeeds(),
allChildren: allChildren[1],
dead,
alivePresent,
Expand Down Expand Up @@ -445,11 +447,13 @@ export class AnalyticService {
childSayName: child.sayname_translations.en,
family: {
familyId: familyId,
activeUsers: removeDuplicates(activeUsersId).length,
activeUsersInOneMonths: removeDuplicates(activeUsersIdInOneMonths)
.length,
activeUsersInThreeMonths: removeDuplicates(activeUsersIdInThreeMonths)
.length,
activeUsers: removeSpecialDuplicates(activeUsersId).length,
activeUsersInOneMonths: removeSpecialDuplicates(
activeUsersIdInOneMonths,
).length,
activeUsersInThreeMonths: removeSpecialDuplicates(
activeUsersIdInThreeMonths,
).length,
familyCount: familyCount,
},
});
Expand Down
34 changes: 34 additions & 0 deletions src/features/campaign/campaign.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Req, ForbiddenException } from '@nestjs/common';
import { ApiHeader, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { FlaskUserTypesEnum } from 'src/types/interfaces/interface';
import { isAuthenticated } from 'src/utils/auth';
import { CampaignService } from './campaign.service';

@ApiTags('Campaign')
@ApiSecurity('flask-access-token')
@ApiHeader({
name: 'flaskId',
description: 'to use cache and flask authentication',
required: true,
})
@Controller('campaign')
export class CampaignController {
constructor(private readonly campaignService: CampaignService) {}

@Get('/all')
getAvailableContributions(@Req() req: Request) {
const panelFlaskUserId = req.headers['panelFlaskUserId'];
const panelFlaskTypeId = req.headers['panelFlaskTypeId'];
if (
!isAuthenticated(panelFlaskUserId, panelFlaskTypeId) ||
!(
panelFlaskTypeId === FlaskUserTypesEnum.SUPER_ADMIN ||
panelFlaskTypeId === FlaskUserTypesEnum.ADMIN
)
) {
throw new ForbiddenException(403, 'You Are not authorized');
}

return this.campaignService.getCampaigns();
}
}
Loading

0 comments on commit b33f639

Please sign in to comment.