Skip to content

Commit

Permalink
Merge pull request #603 from code4romania/develop
Browse files Browse the repository at this point in the history
Release v1.1.1
  • Loading branch information
dragos1195 authored Aug 5, 2024
2 parents 13f440c + 230832a commit 0889966
Show file tree
Hide file tree
Showing 78 changed files with 2,841 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class BalanceSheetAndNonPoliticalAffiliation1721632351165
implements MigrationInterface
{
name = 'BalanceSheetAndNonPoliticalAffiliation1721632351165';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_legal" ADD "balance_sheet_file" character varying`,
);
await queryRunner.query(
`ALTER TABLE "organization_legal" ADD "non_political_affiliation_file" character varying`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_legal" DROP COLUMN "non_political_affiliation_file"`,
);
await queryRunner.query(
`ALTER TABLE "organization_legal" DROP COLUMN "balance_sheet_file"`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddOrganizationAliasToUserApplicationsView1721741119685
implements MigrationInterface
{
name = 'AddOrganizationAliasToUserApplicationsView1721741119685';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`,
['VIEW', 'UserApplicationsView', 'public'],
);
await queryRunner.query(`DROP VIEW "UserApplicationsView"`);
await queryRunner.query(`CREATE VIEW "UserApplicationsView" AS
SELECT u.id,
u.name,
u.email,
u.phone,
u.status,
u.role,
u.organization_id AS "organizationId",
u.created_on AS "createdOn",
u.updated_on AS "updatedOn",
og.alias as "organizationAlias",
array_agg(DISTINCT a.id) AS "availableAppsIDs",
json_agg(DISTINCT jsonb_build_object('id', a.id, 'name', a.name, 'type', a.type)) AS "availableApps"
FROM "user" u
LEFT JOIN user_ong_application uoa ON u.id = uoa.user_id AND uoa.status = 'active'::user_ong_application_status_enum
LEFT JOIN ong_application oa ON uoa.ong_application_id = oa.id AND oa.status = 'active'::ong_application_status_enum
LEFT JOIN application a ON (oa.application_id = a.id OR a.type = 'independent'::application_type_enum) AND a.status = 'active'::application_status_enum
LEFT JOIN organization o ON u.organization_id = o.id
LEFT JOIN organization_general og ON o.organization_general_id = og.id
WHERE u.role = 'employee'::user_role_enum AND (u.status = ANY (ARRAY['active'::user_status_enum, 'restricted'::user_status_enum])) AND u.deleted_on IS NULL
GROUP BY u.id, og.alias;
`);
await queryRunner.query(
`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`,
[
'public',
'VIEW',
'UserApplicationsView',
"SELECT u.id,\n u.name,\n u.email,\n u.phone,\n u.status,\n u.role,\n u.organization_id AS \"organizationId\",\n u.created_on AS \"createdOn\",\n u.updated_on AS \"updatedOn\",\n og.alias as \"organizationAlias\",\n array_agg(DISTINCT a.id) AS \"availableAppsIDs\",\n json_agg(DISTINCT jsonb_build_object('id', a.id, 'name', a.name, 'type', a.type)) AS \"availableApps\"\n FROM \"user\" u\n LEFT JOIN user_ong_application uoa ON u.id = uoa.user_id AND uoa.status = 'active'::user_ong_application_status_enum\n LEFT JOIN ong_application oa ON uoa.ong_application_id = oa.id AND oa.status = 'active'::ong_application_status_enum\n LEFT JOIN application a ON (oa.application_id = a.id OR a.type = 'independent'::application_type_enum) AND a.status = 'active'::application_status_enum\n LEFT JOIN organization o ON u.organization_id = o.id\n LEFT JOIN organization_general og ON o.organization_general_id = og.id\n WHERE u.role = 'employee'::user_role_enum AND (u.status = ANY (ARRAY['active'::user_status_enum, 'restricted'::user_status_enum])) AND u.deleted_on IS NULL\n GROUP BY u.id, og.alias;",
],
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`,
['VIEW', 'UserApplicationsView', 'public'],
);
await queryRunner.query(`DROP VIEW "UserApplicationsView"`);
await queryRunner.query(`CREATE VIEW "UserApplicationsView" AS SELECT u.id,
u.name,
u.email,
u.phone,
u.status,
u.role,
u.organization_id AS "organizationId",
u.created_on AS "createdOn",
u.updated_on AS "updatedOn",
og.alias,
array_agg(DISTINCT a.id) AS "availableAppsIDs",
json_agg(DISTINCT jsonb_build_object('id', a.id, 'name', a.name, 'type', a.type)) AS "availableApps"
FROM "user" u
LEFT JOIN user_ong_application uoa ON u.id = uoa.user_id AND uoa.status = 'active'::user_ong_application_status_enum
LEFT JOIN ong_application oa ON uoa.ong_application_id = oa.id AND oa.status = 'active'::ong_application_status_enum
LEFT JOIN application a ON (oa.application_id = a.id OR a.type = 'independent'::application_type_enum) AND a.status = 'active'::application_status_enum
LEFT JOIN organization o ON u.organization_id = o.id
LEFT JOIN organization_general og ON o.organization_general_id = og.id
WHERE u.role = 'employee'::user_role_enum AND (u.status = ANY (ARRAY['active'::user_status_enum, 'restricted'::user_status_enum])) AND u.deleted_on IS NULL
GROUP BY u.id, og.alias;`);
await queryRunner.query(
`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`,
[
'public',
'VIEW',
'UserApplicationsView',
"SELECT u.id,\n u.name,\n u.email,\n u.phone,\n u.status,\n u.role,\n u.organization_id AS \"organizationId\",\n u.created_on AS \"createdOn\",\n u.updated_on AS \"updatedOn\",\n og.alias,\n array_agg(DISTINCT a.id) AS \"availableAppsIDs\",\n json_agg(DISTINCT jsonb_build_object('id', a.id, 'name', a.name, 'type', a.type)) AS \"availableApps\"\n FROM \"user\" u\n LEFT JOIN user_ong_application uoa ON u.id = uoa.user_id AND uoa.status = 'active'::user_ong_application_status_enum\n LEFT JOIN ong_application oa ON uoa.ong_application_id = oa.id AND oa.status = 'active'::ong_application_status_enum\n LEFT JOIN application a ON (oa.application_id = a.id OR a.type = 'independent'::application_type_enum) AND a.status = 'active'::application_status_enum\n LEFT JOIN organization o ON u.organization_id = o.id\n LEFT JOIN organization_general og ON o.organization_general_id = og.id\n WHERE u.role = 'employee'::user_role_enum AND (u.status = ANY (ARRAY['active'::user_status_enum, 'restricted'::user_status_enum])) AND u.deleted_on IS NULL\n GROUP BY u.id, og.alias;",
],
);
}
}
34 changes: 34 additions & 0 deletions backend/src/migrations/1721829705666-AddIssuer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { ISSUERS } from './seed/issuers.seed';
import { Issuer } from 'src/shared/entities';
export class AddIssuer1721829705666 implements MigrationInterface {
name = 'AddIssuer1721829705666';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "_issuer" ("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_cfe878b7aa3dc098f2ac736adc6" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE INDEX "IDX_20b3d0cad6a13638d5d485eada" ON "_issuer" ("created_on") `,
);
await queryRunner.manager
.createQueryBuilder()
.insert()
.into(Issuer)
.values(ISSUERS)
.execute();
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager
.createQueryBuilder()
.delete()
.from(Issuer)
.execute();

await queryRunner.query(
`DROP INDEX "public"."IDX_20b3d0cad6a13638d5d485eada"`,
);
await queryRunner.query(`DROP TABLE "_issuer"`);
}
}
53 changes: 53 additions & 0 deletions backend/src/migrations/1721899705666-NewGeneralFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class NewGeneralFields1721899705666 implements MigrationInterface {
name = 'NewGeneralFields1721899705666';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_general" ALTER COLUMN "raf_number" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD "association_registry_number" text`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD "association_registry_part" text`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD "association_registry_section" text`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD "association_registry_issuer_id" integer`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD CONSTRAINT "FK_302f085592ed8a6c5d06f1182ef" FOREIGN KEY ("association_registry_issuer_id") REFERENCES "_issuer"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" ADD "national_registry_number" text`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "organization_general" ALTER COLUMN "raf_number" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP COLUMN "national_registry_number"`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP CONSTRAINT "FK_302f085592ed8a6c5d06f1182ef"`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP COLUMN "association_registry_issuer_id"`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP COLUMN "association_registry_section"`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP COLUMN "association_registry_part"`,
);
await queryRunner.query(
`ALTER TABLE "organization_general" DROP COLUMN "association_registry_number"`,
);
}
}
27 changes: 27 additions & 0 deletions backend/src/migrations/1722099705666-SectorsSeed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { City } from 'src/shared/entities';
import { MigrationInterface, QueryRunner } from 'typeorm';
import { SECTORS } from './seed/sectors.seed';

export class SectorsSeed1722099705666 implements MigrationInterface {
name = 'SectorsSeed1722099705666';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager
.createQueryBuilder()
.insert()
.into(City)
.values(SECTORS)
.execute();
}

public async down(queryRunner: QueryRunner): Promise<void> {
const sectorIds = SECTORS.map((sector) => sector.id);

await queryRunner.manager
.createQueryBuilder()
.delete()
.from(City)
.where('id IN (:...ids)', { ids: sectorIds })
.execute();
}
}
13 changes: 13 additions & 0 deletions backend/src/migrations/1722423180665-ContactRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ContactRole1722423180665 implements MigrationInterface {
name = 'ContactRole1722423180665';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "_contact" ADD "role" text`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "_contact" DROP COLUMN "role"`);
}
}
10 changes: 5 additions & 5 deletions backend/src/migrations/seed/city.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8899,11 +8899,11 @@ export const CITIES = [
countyId: 33,
name: 'Bucuresci',
},
{
id: 1781,
countyId: 11,
name: 'Bucuresti',
},
// {
// id: 1781,
// countyId: 11,
// name: 'Bucuresti',
// },
{
id: 1782,
countyId: 6,
Expand Down
Loading

0 comments on commit 0889966

Please sign in to comment.