-
-
Notifications
You must be signed in to change notification settings - Fork 5
Labels for Applications #608
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
Changes from all commits
4ae6a1a
a8bf1e9
d680de2
5a463a1
819271b
293b1a1
8031f6c
6711a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class ApplicationLabel1723119327053 implements MigrationInterface { | ||
| name = 'ApplicationLabel1723119327053'; | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `CREATE TABLE "_application-label" ("id" SERIAL NOT NULL, "deleted_on" TIMESTAMP WITH TIME ZONE, "created_on" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_on" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "name" text NOT NULL, CONSTRAINT "PK_c0aaf1127ad3beeaf0d3ad70096" PRIMARY KEY ("id"))`, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE INDEX "IDX_e4a4e4b1582c4e665cff9be33e" ON "_application-label" ("created_on") `, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "application" ADD "application_label_id" integer`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "application" ADD CONSTRAINT "FK_318029631a770782ba1c66721fd" FOREIGN KEY ("application_label_id") REFERENCES "_application-label"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query( | ||
| `ALTER TABLE "application" DROP CONSTRAINT "FK_318029631a770782ba1c66721fd"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "application" DROP COLUMN "application_label_id"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `DROP INDEX "public"."IDX_e4a4e4b1582c4e665cff9be33e"`, | ||
| ); | ||
| await queryRunner.query(`DROP TABLE "_application-label"`); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ import { ApplicationTableViewRepository } from '../repositories/application-tabl | |
| import { ApplicationRepository } from '../repositories/application.repository'; | ||
| import { OngApplicationRepository } from '../repositories/ong-application.repository'; | ||
| import { UserOngApplicationRepository } from '../repositories/user-ong-application.repository'; | ||
| import { ApplicationLabel } from 'src/shared/entities/application-labels.entity'; | ||
| import { NomenclaturesService } from 'src/shared/services'; | ||
|
|
||
| @Injectable() | ||
| export class ApplicationService { | ||
|
|
@@ -49,6 +51,7 @@ export class ApplicationService { | |
| private readonly ongApplicationRepository: OngApplicationRepository, | ||
| private readonly userOngApplicationRepository: UserOngApplicationRepository, | ||
| private readonly applicationOngViewRepository: ApplicationOngViewRepository, | ||
| private readonly nomenclatureService: NomenclaturesService, | ||
| ) {} | ||
|
|
||
| public async create( | ||
|
|
@@ -250,6 +253,7 @@ export class ApplicationService { | |
| 'application.video_link as "videoLink"', | ||
| 'application.pulling_type as "pullingType"', | ||
| 'application.status as "applicationStatus"', | ||
| 'applicationLabel', | ||
| ]) | ||
| .leftJoin( | ||
| 'ong_application', | ||
|
|
@@ -262,6 +266,11 @@ export class ApplicationService { | |
| 'userOngApp', | ||
| 'userOngApp.ong_application_id = ongApp.id', | ||
| ) | ||
| .leftJoin( | ||
| '_application-label', | ||
| 'applicationLabel', | ||
| 'applicationLabel.id = application.application_label_id', | ||
| ) | ||
| .where('application.id = :applicationId', { applicationId }); | ||
|
|
||
| // for employee add further filtersin by user id | ||
|
|
@@ -292,8 +301,19 @@ export class ApplicationService { | |
| ); | ||
| } | ||
|
|
||
| const applicationLabel = { | ||
| id: applicationWithDetails.applicationLabel_id, | ||
| name: applicationWithDetails.applicationLabel_name, | ||
| }; | ||
|
|
||
| delete applicationWithDetails.applicationLabel_id; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nu putem face queryul direct cu id si name ca aliasuri ca sa nu mai facem delete-uri?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este getRawOne, n-am cum sa le scot direct in object.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, am inteles ca vrei sa le pui intr-un obiect direct. Deci chiar daca facem Tot trebuie sa le stergi apoi din @dragos1195 Totusi, mai lipseste |
||
| delete applicationWithDetails.applicationLabel_name; | ||
| delete applicationWithDetails.applicationLabel_created_on; | ||
| delete applicationWithDetails.applicationLabel_updated_on; | ||
|
|
||
| return { | ||
| ...applicationWithDetails, | ||
| applicationLabel, | ||
| logo, | ||
| }; | ||
| } | ||
|
|
@@ -346,7 +366,17 @@ export class ApplicationService { | |
| }; | ||
| } | ||
|
|
||
| return this.applicationRepository.update({ id }, applicationPayload); | ||
| let applicationLabel = null; | ||
| if (applicationPayload.applicationLabel) { | ||
| applicationLabel = await this.saveAndGetApplicationLabel( | ||
| applicationPayload.applicationLabel, | ||
| ); | ||
| } | ||
|
|
||
| return this.applicationRepository.update( | ||
| { id }, | ||
| { ...applicationPayload, applicationLabel }, | ||
| ); | ||
| } catch (error) { | ||
| this.logger.error({ | ||
| error: { error }, | ||
|
|
@@ -502,4 +532,17 @@ export class ApplicationService { | |
|
|
||
| return applicationCount; | ||
| } | ||
|
|
||
| private async saveAndGetApplicationLabel( | ||
| label: Partial<ApplicationLabel>, | ||
| ): Promise<ApplicationLabel> { | ||
| if (label.id) { | ||
| return label as ApplicationLabel; | ||
| } | ||
|
|
||
| const newLabel = | ||
| await this.nomenclatureService.createApplicationLabel(label); | ||
|
|
||
| return newLabel; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { BaseEntity } from 'src/common/base/base-entity.class'; | ||
| import { Column, Entity } from 'typeorm'; | ||
|
|
||
| @Entity({ name: '_application-label' }) | ||
| export class ApplicationLabel extends BaseEntity { | ||
| @Column({ type: 'text', name: 'name' }) | ||
| name: string; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.