Skip to content

Commit

Permalink
SPSH-343 Use UUIDs everywhere (#341)
Browse files Browse the repository at this point in the history
* Use UUIDs everywhere

* Fix seeding data
  • Loading branch information
marode-cap authored Mar 7, 2024
1 parent cc9b50e commit 297b168
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 49 deletions.
6 changes: 3 additions & 3 deletions charts/dbildungs-iam-server/seeding/dev/04_rolle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"entities": [
{
"id": "cef7240e-fd08-4961-927e-c9ea0c5a37c5",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 1",
"rollenart": "LERN",
"merkmale": []
},
{
"id": "6a69fadb-af89-42ed-ae12-28d164c0f9b7",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 2",
"rollenart": "LERN",
"merkmale": []
},
{
"id": "a9c2a6e5-8211-4d6d-a6e7-b4e3af473bce",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 3",
"rollenart": "LEHR",
"merkmale": []
Expand Down
6 changes: 3 additions & 3 deletions sql/dev/04_rolle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"entities": [
{
"id": "cef7240e-fd08-4961-927e-c9ea0c5a37c5",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 1",
"rollenart": "LERN",
"merkmale": []
},
{
"id": "6a69fadb-af89-42ed-ae12-28d164c0f9b7",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 2",
"rollenart": "LERN",
"merkmale": []
},
{
"id": "a9c2a6e5-8211-4d6d-a6e7-b4e3af473bce",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "d39cb7cf-2f9b-45f1-849f-973661f2f057",
"name": "Rolle 3",
"rollenart": "LEHR",
"merkmale": []
Expand Down
4 changes: 2 additions & 2 deletions sql/seeding-integration-test/all/03_service-provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"kategorie": "UNTERRICHT",
"logoMimeType": "image/png",
"logoBase64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg==",
"providedOnSchulstrukturknoten": "1"
"providedOnSchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54"
},
{
"id": "d96ddc00-a8ed-4d4c-b498-24958fb64604",
"name": "Provider Without Logo",
"url": "https://example.com/",
"kategorie": "UNTERRICHT",
"providedOnSchulstrukturknoten": "1"
"providedOnSchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54"
}
]
}
2 changes: 1 addition & 1 deletion sql/seeding-integration-test/all/04_rolle.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"id": "301457e9-4fe5-42a6-8084-fec927dc00df",
"name": "Rolle2222",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54",
"rollenart": "LERN",
"merkmale": []
}
Expand Down
2 changes: 1 addition & 1 deletion sql/seeding-integration-test/newRolle/04_rolle.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"id": "3ca85c16-96b2-46c8-a4fd-27e73d7ab96c",
"name": "Rolle9988",
"administeredBySchulstrukturknoten": "1",
"administeredBySchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54",
"rollenart": "LERN",
"merkmale": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"kategorie": "UNTERRICHT",
"logoMimeType": "image/png",
"logoBase64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg==",
"providedOnSchulstrukturknoten": "1"
"providedOnSchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54"
},
{
"name": "E-Mail",
"url": "https://de.wikipedia.org/wiki/E-Mail",
"kategorie": "EMAIL",
"logoMimeType": "image/png",
"logoBase64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR4AWNgAAAAAgABc3UBGAAAAABJRU5ErkJggg==",
"providedOnSchulstrukturknoten": "1"
"providedOnSchulstrukturknoten": "cb3e7c7f-c8fb-4083-acbf-2484efb19b54"
}
]
}
8 changes: 5 additions & 3 deletions src/console/dbseed/db-seed.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('DbSeedService', () => {
const rolle: Partial<Rolle<true>> = {
id: '301457e9-4fe5-42a6-8084-fec927dc00df',
name: 'Rolle2222',
administeredBySchulstrukturknoten: '1',
administeredBySchulstrukturknoten: 'cb3e7c7f-c8fb-4083-acbf-2484efb19b54',
rollenart: RollenArt.LERN,
merkmale: [],
createdAt: expect.any(Date) as Date,
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('DbSeedService', () => {
kategorie: ServiceProviderKategorie.UNTERRICHT,
logoMimeType: 'image/png',
logo: expect.any(Buffer) as Buffer,
providedOnSchulstrukturknoten: '1',
providedOnSchulstrukturknoten: 'cb3e7c7f-c8fb-4083-acbf-2484efb19b54',
createdAt: expect.any(Date) as Date,
updatedAt: expect.any(Date) as Date,
});
Expand All @@ -175,7 +175,9 @@ describe('DbSeedService', () => {
name: 'Provider Without Logo',
url: 'https://example.com/',
kategorie: ServiceProviderKategorie.UNTERRICHT,
providedOnSchulstrukturknoten: '1',
logo: undefined,
logoMimeType: undefined,
providedOnSchulstrukturknoten: 'cb3e7c7f-c8fb-4083-acbf-2484efb19b54',
createdAt: expect.any(Date) as Date,
updatedAt: expect.any(Date) as Date,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { AutoMap } from '@automapper/classes';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { IsEnum, IsOptional, IsString, IsUUID } from 'class-validator';
import { OrganisationsTyp, Traegerschaft } from '../domain/organisation.enums.js';

export class CommonCreateUpdateOrganisationBodyParams {
@AutoMap()
@IsOptional()
@IsString()
@IsUUID()
@ApiPropertyOptional()
public readonly administriertVon?: string;

@AutoMap()
@IsOptional()
@IsString()
@IsUUID()
@ApiPropertyOptional()
public readonly zugehoerigZu?: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { IsUUID } from 'class-validator';

export class OrganisationByIdBodyParams {
@IsString()
@IsUUID()
@ApiProperty({
description: 'The id of an organization',
required: true,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/organisation/api/organisation-by-id.params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { IsUUID } from 'class-validator';

export class OrganisationByIdParams {
@IsString()
@IsUUID()
@ApiProperty({
description: 'The id of an organization',
required: true,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/organisation/persistence/organisation.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export class OrganisationEntity extends TimestampedEntity {
}

@AutoMap()
@Property({ nullable: true })
@Property({ columnType: 'uuid', nullable: true })
public administriertVon?: string;

@AutoMap()
@Property({ nullable: true })
@Property({ columnType: 'uuid', nullable: true })
public zugehoerigZu?: string;

@AutoMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ describe('OrganisationSpecificationTests', () => {
});
traeger1 = await repo.save(traeger);
traeger = DoFactory.createOrganisation(false, {
id: '2',
name: 'Traeger2',
typ: OrganisationsTyp.TRAEGER,
administriertVon: traeger1.id,
zugehoerigZu: traeger1.id,
});
traeger2 = await repo.save(traeger);
traeger = DoFactory.createOrganisation(false, {
id: '3',
name: 'Traeger3',
typ: OrganisationsTyp.TRAEGER,
administriertVon: traeger2.id,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/person/api/person-by-id.param.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IsString } from 'class-validator';
import { IsUUID } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class PersonByIdParams {
@IsString()
@IsUUID()
@ApiProperty({
description: 'The id for the account.',
required: true,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/personenkontext/api/delete-personkontext.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AutoMap } from '@automapper/classes';
import { IsNotEmpty } from 'class-validator';
import { IsUUID } from 'class-validator';

export class DeletePersonenkontextDto {
@AutoMap()
@IsNotEmpty()
@IsUUID()
public id!: string;

@AutoMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ describe('dbiam Personenkontext Repo', () => {

describe('findByPerson', () => {
it('should return all personenkontexte for a person', async () => {
const personA: string = faker.string.uuid();
const personB: string = faker.string.uuid();

await Promise.all([
sut.save(createPersonenkontext(false, { personId: '0' })),
sut.save(createPersonenkontext(false, { personId: '1' })),
sut.save(createPersonenkontext(false, { personId: personA })),
sut.save(createPersonenkontext(false, { personId: personB })),
]);

const personenkontexte: Personenkontext<true>[] = await sut.findByPerson('0');
const personenkontexte: Personenkontext<true>[] = await sut.findByPerson(personA);

expect(personenkontexte).toHaveLength(1);
});
Expand All @@ -85,7 +88,7 @@ describe('dbiam Personenkontext Repo', () => {
});

it('should return false, if the triplet does not exists', async () => {
const exists: boolean = await sut.exists('', '', '');
const exists: boolean = await sut.exists(faker.string.uuid(), faker.string.uuid(), faker.string.uuid());

expect(exists).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { Jahrgangsstufe, Personenstatus, Rolle, SichtfreigabeType } from '../dom
@Unique({ properties: ['personId', 'organisationId', 'rolleId'] })
export class PersonenkontextEntity extends TimestampedEntity {
@AutoMap()
@Property({ nullable: false })
@Property({ columnType: 'uuid', nullable: false })
public personId!: string;

// TODO EW-636: get from access_token, see SchulConneX (Version 1.003.003.000) page 91
@AutoMap()
@Property({ nullable: true })
@Property({ columnType: 'uuid', nullable: true })
public organisationId!: string;

// Will be mandatory soon. PersonenkontextAggregate will always set ID.
@Property({ nullable: true })
@Property({ columnType: 'uuid', nullable: true })
public rolleId!: string;

@AutoMap()
Expand Down
2 changes: 1 addition & 1 deletion src/modules/rolle/entity/rolle.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class RolleEntity extends TimestampedEntity {
/**
* Points to Schulstrukturknoten
*/
@Property()
@Property({ columnType: 'uuid' })
public administeredBySchulstrukturknoten!: string;

@Enum(() => RollenArt)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/service-provider/api/angebot-by.id.params.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { IsUUID } from 'class-validator';

export class AngebotByIdParams {
@IsString()
@IsUUID()
@ApiProperty({
description: 'The id of the service provider',
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('ServiceProvider API', () => {

describe('when the service provider does not exist', () => {
it('should return 404', async () => {
const serviceProvider: ServiceProvider<false> = DoFactory.createServiceProvider(false);
const serviceProvider: ServiceProvider<true> = DoFactory.createServiceProvider(true);

const response: Response = await request(app.getHttpServer() as App)
.get(`/provider/${serviceProvider.id}/logo`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ServiceProviderEntity extends TimestampedEntity {
@Property()
public url!: string;

@Property()
@Property({ columnType: 'uuid' })
public providedOnSchulstrukturknoten!: string;

@Enum(() => ServiceProviderKategorie)
Expand Down
4 changes: 2 additions & 2 deletions src/persistence/benachrichtigung.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export class BenachrichtigungEntity extends TimestampedEntity {
/**
* Links to Person
*/
@Property()
@Property({ columnType: 'uuid' })
public source!: string;

/**
* Links to Person
*/
@Property()
@Property({ columnType: 'uuid' })
public target!: string;
}
6 changes: 3 additions & 3 deletions src/persistence/schulstrukturknoten.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { Entity, OneToOne, Property } from '@mikro-orm/core';
discriminatorMap: { traeger: 'traeger', organisation: 'organisation', group: 'gruppe' },
})
export abstract class SchulstrukturknotenEntity extends TimestampedEntity {
@OneToOne()
@OneToOne({ columnType: 'uuid' })
public administrativeParent?: SchulstrukturknotenEntity;

@OneToOne()
@OneToOne({ columnType: 'uuid' })
public organizationalParent?: SchulstrukturknotenEntity;

/**
* Points to DataProvider
*/
@Property()
@Property({ columnType: 'uuid' })
public dataProvider?: string;
}
2 changes: 1 addition & 1 deletion src/persistence/timestamped.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { randomUUID } from 'crypto';

export abstract class TimestampedEntity extends BaseEntity {
@AutoMap()
@PrimaryKey({ onCreate: () => randomUUID() })
@PrimaryKey({ columnType: 'uuid', onCreate: () => randomUUID() })
public readonly id!: string;

@AutoMap(() => Date)
Expand Down
2 changes: 1 addition & 1 deletion test/utils/do-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class DoFactory {
): RolleAggregate<WasPersisted> {
const rolle: Partial<RolleAggregate<WasPersisted>> = {
name: faker.person.jobTitle(),
administeredBySchulstrukturknoten: faker.string.numeric(),
administeredBySchulstrukturknoten: faker.string.uuid(),
rollenart: faker.helpers.enumValue(RollenArt),
merkmale: [faker.helpers.enumValue(RollenMerkmal)],
id: withId ? faker.string.uuid() : undefined,
Expand Down

0 comments on commit 297b168

Please sign in to comment.