feat: set theme for junior users

This commit is contained in:
Abdalhamid Alhamad
2024-12-10 09:23:30 +03:00
parent c2f63ccc72
commit 7ed37c30e1
30 changed files with 302 additions and 14 deletions

View File

@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateThemeEntity1733748083604 implements MigrationInterface {
name = 'CreateThemeEntity1733748083604';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "themes"
("id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"color" character varying(255) NOT NULL,
"avatar_id" uuid, "junior_id" uuid NOT NULL,
CONSTRAINT "REL_73fcb76399a308cdd2d431a8f2" UNIQUE ("junior_id"),
CONSTRAINT "PK_ddbeaab913c18682e5c88155592" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "themes" ADD CONSTRAINT "FK_169b672cc28cc757e1f4464864d" FOREIGN KEY ("avatar_id") REFERENCES "documents"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "themes" ADD CONSTRAINT "FK_73fcb76399a308cdd2d431a8f2e" FOREIGN KEY ("junior_id") REFERENCES "juniors"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "themes" DROP CONSTRAINT "FK_73fcb76399a308cdd2d431a8f2e"`);
await queryRunner.query(`ALTER TABLE "themes" DROP CONSTRAINT "FK_169b672cc28cc757e1f4464864d"`);
await queryRunner.query(`DROP TABLE "themes"`);
}
}

View File

@ -0,0 +1,73 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import { v4 as uuid } from 'uuid';
import { Document } from '../../document/entities';
import { DocumentType } from '../../document/enums';
const DEFAULT_AVATARS = [
{
id: uuid(),
name: 'vacation',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'colors',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'astronaut',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'pet',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'disney',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'clothes',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'playstation',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'football',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
{
id: uuid(),
name: 'cars',
extension: '.jpg',
documentType: DocumentType.DEFAULT_AVATAR,
},
];
export class SeedDefaultAvatar1733750228289 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.getRepository(Document).save(DEFAULT_AVATARS);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await DEFAULT_AVATARS.forEach(async (avatar) => {
await queryRunner.manager
.getRepository(Document)
.delete({ name: avatar.name, documentType: avatar.documentType });
});
}
}

View File

@ -6,3 +6,5 @@ export * from './1733298524771-create-customer-entity';
export * from './1733314952318-create-device-entity';
export * from './1733731507261-create-junior-entity';
export * from './1733732021622-create-guardian-entity';
export * from './1733748083604-create-theme-entity';
export * from './1733750228289-seed-default-avatar';