Skip to content

Commit

Permalink
mail service
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 5, 2023
1 parent 1c6fb79 commit 60c1624
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 62 deletions.
2 changes: 2 additions & 0 deletions src/db/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import config from '../config';
import { AllUserEntity } from 'src/entities/user.entity';
import { ChildrenPreRegisterEntity } from 'src/entities/childrenPreRegister.entity';
import { ContributionEntity } from 'src/entities/contribution.entity';
import { CampaignEntity } from 'src/entities/campaign.entity';

export const postgresDataSourceOptions: DataSourceOptions = {
...config().db1,
entities: [
Session,
AllUserEntity,
CampaignEntity,
LocationEntity,
StatusEntity,
ContributorEntity,
Expand Down
44 changes: 44 additions & 0 deletions src/db/migrations/1699105112698-new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class New1699105112698 implements MigrationInterface {
name = 'New1699105112698'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "campaign_entity" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "title" character varying NOT NULL, "campaign" integer NOT NULL, "type" integer NOT NULL, CONSTRAINT "PK_9e02b1f09bf92b8ce7b80e4fb7a" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "campaign_entity_receivers_all_user_entity" ("campaignEntityId" uuid NOT NULL, "allUserEntityId" uuid NOT NULL, CONSTRAINT "PK_147af3299a0c9fe8859ce754aa0" PRIMARY KEY ("campaignEntityId", "allUserEntityId"))`);
await queryRunner.query(`CREATE INDEX "IDX_c7f9a0ab87070fb14e116587a8" ON "campaign_entity_receivers_all_user_entity" ("campaignEntityId") `);
await queryRunner.query(`CREATE INDEX "IDX_47beff96e36228ba71b277e509" ON "campaign_entity_receivers_all_user_entity" ("allUserEntityId") `);
await queryRunner.query(`CREATE TABLE "campaign_entity_content_signatures_signature_entity" ("campaignEntityId" uuid NOT NULL, "signatureEntityId" uuid NOT NULL, CONSTRAINT "PK_2a6739114fed6e9d81369e83453" PRIMARY KEY ("campaignEntityId", "signatureEntityId"))`);
await queryRunner.query(`CREATE INDEX "IDX_edca9c9d4686a3cb99d20ae497" ON "campaign_entity_content_signatures_signature_entity" ("campaignEntityId") `);
await queryRunner.query(`CREATE INDEX "IDX_e34cd832c86a0366db8a8b9d06" ON "campaign_entity_content_signatures_signature_entity" ("signatureEntityId") `);
await queryRunner.query(`CREATE TABLE "campaign_entity_content_needs_need_entity" ("campaignEntityId" uuid NOT NULL, "needEntityId" uuid NOT NULL, CONSTRAINT "PK_98884604dc03c841798c07824a0" PRIMARY KEY ("campaignEntityId", "needEntityId"))`);
await queryRunner.query(`CREATE INDEX "IDX_65b8cbeda0c8f14d9a97500a1b" ON "campaign_entity_content_needs_need_entity" ("campaignEntityId") `);
await queryRunner.query(`CREATE INDEX "IDX_0863220483cce26ae11a4e9f88" ON "campaign_entity_content_needs_need_entity" ("needEntityId") `);
await queryRunner.query(`ALTER TABLE "campaign_entity_receivers_all_user_entity" ADD CONSTRAINT "FK_c7f9a0ab87070fb14e116587a8d" FOREIGN KEY ("campaignEntityId") REFERENCES "campaign_entity"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE "campaign_entity_receivers_all_user_entity" ADD CONSTRAINT "FK_47beff96e36228ba71b277e509b" FOREIGN KEY ("allUserEntityId") REFERENCES "all_user_entity"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_signatures_signature_entity" ADD CONSTRAINT "FK_edca9c9d4686a3cb99d20ae4978" FOREIGN KEY ("campaignEntityId") REFERENCES "campaign_entity"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_signatures_signature_entity" ADD CONSTRAINT "FK_e34cd832c86a0366db8a8b9d06c" FOREIGN KEY ("signatureEntityId") REFERENCES "signature_entity"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_needs_need_entity" ADD CONSTRAINT "FK_65b8cbeda0c8f14d9a97500a1ba" FOREIGN KEY ("campaignEntityId") REFERENCES "campaign_entity"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_needs_need_entity" ADD CONSTRAINT "FK_0863220483cce26ae11a4e9f88d" FOREIGN KEY ("needEntityId") REFERENCES "need_entity"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "campaign_entity_content_needs_need_entity" DROP CONSTRAINT "FK_0863220483cce26ae11a4e9f88d"`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_needs_need_entity" DROP CONSTRAINT "FK_65b8cbeda0c8f14d9a97500a1ba"`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_signatures_signature_entity" DROP CONSTRAINT "FK_e34cd832c86a0366db8a8b9d06c"`);
await queryRunner.query(`ALTER TABLE "campaign_entity_content_signatures_signature_entity" DROP CONSTRAINT "FK_edca9c9d4686a3cb99d20ae4978"`);
await queryRunner.query(`ALTER TABLE "campaign_entity_receivers_all_user_entity" DROP CONSTRAINT "FK_47beff96e36228ba71b277e509b"`);
await queryRunner.query(`ALTER TABLE "campaign_entity_receivers_all_user_entity" DROP CONSTRAINT "FK_c7f9a0ab87070fb14e116587a8d"`);
await queryRunner.query(`DROP INDEX "public"."IDX_0863220483cce26ae11a4e9f88"`);
await queryRunner.query(`DROP INDEX "public"."IDX_65b8cbeda0c8f14d9a97500a1b"`);
await queryRunner.query(`DROP TABLE "campaign_entity_content_needs_need_entity"`);
await queryRunner.query(`DROP INDEX "public"."IDX_e34cd832c86a0366db8a8b9d06"`);
await queryRunner.query(`DROP INDEX "public"."IDX_edca9c9d4686a3cb99d20ae497"`);
await queryRunner.query(`DROP TABLE "campaign_entity_content_signatures_signature_entity"`);
await queryRunner.query(`DROP INDEX "public"."IDX_47beff96e36228ba71b277e509"`);
await queryRunner.query(`DROP INDEX "public"."IDX_c7f9a0ab87070fb14e116587a8"`);
await queryRunner.query(`DROP TABLE "campaign_entity_receivers_all_user_entity"`);
await queryRunner.query(`DROP TABLE "campaign_entity"`);
}

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

export class New1699105844419 implements MigrationInterface {
name = 'New1699105844419'

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")`);
}

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"`);
}

}
39 changes: 39 additions & 0 deletions src/entities/campaign.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 { SignatureEntity } from './signature.entity';
import { NeedEntity } from './need.entity';

@Entity()
export class CampaignEntity extends BaseEntity {
@Column({ nullable: false })
title: string;

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

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

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

@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[];
}
14 changes: 13 additions & 1 deletion src/entities/need.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Entity, Column, Index, OneToMany, ManyToOne, OneToOne } from 'typeorm';
import {
Entity,
Column,
Index,
OneToMany,
ManyToOne,
OneToOne,
ManyToMany,
} from 'typeorm';
import { ProviderEntity } from './provider.entity';
import { ChildrenEntity } from './children.entity';
import { PaymentEntity } from './payment.entity';
Expand All @@ -14,6 +22,7 @@ import { SignatureEntity } from './signature.entity';
import { CommentEntity } from './comment.entity';
import { VariableEntity } from './variable.entity';
import { EthereumTransaction } from './ethereum.transaction.entity';
import { CampaignEntity } from './campaign.entity';

@Entity()
export class NeedEntity extends BaseEntity {
Expand Down Expand Up @@ -170,4 +179,7 @@ export class NeedEntity extends BaseEntity {

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

@ManyToMany(() => CampaignEntity, (c) => c.contentNeeds)
campaigns: CampaignEntity[];
}
6 changes: 5 additions & 1 deletion src/entities/signature.entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Entity, Column, ManyToOne } from 'typeorm';
import { Entity, Column, ManyToOne, ManyToMany } from 'typeorm';
import { SAYPlatformRoles } from '../types/interfaces/interface';
import { BaseEntity } from './BaseEntity';
import { NeedEntity } from './need.entity';
import { AllUserEntity } from './user.entity';
import { CampaignEntity } from './campaign.entity';

@Entity()
export class SignatureEntity extends BaseEntity {
Expand Down Expand Up @@ -38,4 +39,7 @@ export class SignatureEntity extends BaseEntity {
nullable: false,
})
need: NeedEntity;

@ManyToMany(() => CampaignEntity, (c) => c.contentNeeds)
campaigns: CampaignEntity[];
}
2 changes: 1 addition & 1 deletion src/entities/ticket.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TicketEntity extends BaseEntity {
@Column({ nullable: true })
lastAnnouncement: AnnouncementEnum

@ManyToMany(() => AllUserEntity, (user) => user.tickets, { eager: true, onDelete: 'CASCADE' })
@ManyToMany(() => AllUserEntity, (user) => user.tickets, { eager: true })
@JoinTable()
contributors?: AllUserEntity[];

Expand Down
9 changes: 9 additions & 0 deletions src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TicketEntity } from './ticket.entity';
import { ContributorEntity } from './contributor.entity';
import { SignatureEntity } from './signature.entity';
import { CommentEntity } from './comment.entity';
import { CampaignEntity } from './campaign.entity';

@Entity()
export class AllUserEntity extends BaseEntity {
Expand All @@ -28,6 +29,9 @@ export class AllUserEntity extends BaseEntity {
})
comments: CommentEntity[];

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

@Column({ nullable: false })
isContributor: boolean;

Expand Down Expand Up @@ -63,4 +67,9 @@ export class AllUserEntity extends BaseEntity {

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

@OneToMany(() => CampaignEntity, (e) => e.receivers, {
eager: false,
})
receivedEmails: CampaignEntity[];
}
2 changes: 2 additions & 0 deletions src/features/mail/mail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { MineService } from '../mine/mine.service';
import { PaymentEntity } from 'src/entities/payment.entity';
import { Family } from 'src/entities/flaskEntities/family.entity';
import { UserFamily } from 'src/entities/flaskEntities/userFamily.entity';
import { CampaignEntity } from 'src/entities/campaign.entity';

@Global() // 👈 global module
@Module({
Expand Down Expand Up @@ -70,6 +71,7 @@ import { UserFamily } from 'src/entities/flaskEntities/userFamily.entity';
SignatureEntity,
PaymentEntity,
AllUserEntity,
CampaignEntity,
]),
],
providers: [
Expand Down
Loading

0 comments on commit 60c1624

Please sign in to comment.