101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
export class ApplicationData {
|
|
private constructor(
|
|
public readonly id: string,
|
|
public code: string,
|
|
public name: string,
|
|
public description: string | null,
|
|
public icon: string | null,
|
|
public url: string | null,
|
|
public applicationsClaim: string,
|
|
public isActive: boolean,
|
|
public displayOrder: number,
|
|
public createdAt: Date | null,
|
|
public updatedAt: Date | null,
|
|
) {}
|
|
|
|
static create(data: {
|
|
code: string;
|
|
name: string;
|
|
description?: string | null;
|
|
icon?: string | null;
|
|
url?: string | null;
|
|
applicationsClaim: string;
|
|
displayOrder?: number;
|
|
}) {
|
|
return new ApplicationData(
|
|
crypto.randomUUID(),
|
|
data.code,
|
|
data.name,
|
|
data.description ?? null,
|
|
data.icon ?? null,
|
|
data.url ?? null,
|
|
data.applicationsClaim,
|
|
true,
|
|
data.displayOrder ?? 0,
|
|
new Date(),
|
|
new Date(),
|
|
);
|
|
}
|
|
|
|
static restore(props: {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
description?: string | null;
|
|
icon?: string | null;
|
|
url?: string | null;
|
|
applicationsClaim: string;
|
|
isActive?: boolean;
|
|
displayOrder?: number;
|
|
createdAt?: Date | null;
|
|
updatedAt?: Date | null;
|
|
}) {
|
|
return new ApplicationData(
|
|
props.id,
|
|
props.code,
|
|
props.name,
|
|
props.description ?? null,
|
|
props.icon ?? null,
|
|
props.url ?? null,
|
|
props.applicationsClaim,
|
|
props.isActive !== undefined ? props.isActive : true,
|
|
props.displayOrder ?? 0,
|
|
props.createdAt ?? null,
|
|
props.updatedAt ?? null,
|
|
);
|
|
}
|
|
|
|
update(data: {
|
|
code?: string;
|
|
name?: string;
|
|
description?: string | null;
|
|
icon?: string | null;
|
|
url?: string | null;
|
|
applicationsClaim?: string;
|
|
isActive?: boolean;
|
|
displayOrder?: number;
|
|
}) {
|
|
if (data.code !== undefined) this.code = data.code;
|
|
if (data.name !== undefined) this.name = data.name;
|
|
if (data.description !== undefined) this.description = data.description;
|
|
if (data.icon !== undefined) this.icon = data.icon;
|
|
if (data.url !== undefined) this.url = data.url;
|
|
if (data.applicationsClaim !== undefined) this.applicationsClaim = data.applicationsClaim;
|
|
if (data.isActive !== undefined) this.isActive = data.isActive;
|
|
if (data.displayOrder !== undefined) this.displayOrder = data.displayOrder;
|
|
this.updatedAt = new Date();
|
|
}
|
|
|
|
toResponse() {
|
|
return {
|
|
id: this.id,
|
|
code: this.code,
|
|
name: this.name,
|
|
description: this.description,
|
|
icon: this.icon,
|
|
url: this.url,
|
|
displayOrder: this.displayOrder,
|
|
};
|
|
}
|
|
}
|