add basic repo setup, with user creation

This commit is contained in:
mrjvs
2023-10-28 16:49:02 +02:00
parent 9166c37aea
commit 94e1f9ebe1
26 changed files with 5762 additions and 374 deletions

31
src/db/models/User.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Entity, PrimaryKey, Property, types } from '@mikro-orm/core';
import { randomUUID } from 'crypto';
@Entity({ tableName: 'users' })
export class User {
@PrimaryKey({ name: 'id', type: 'uuid' })
id: string = randomUUID();
@Property({ type: 'date' })
createdAt: Date = new Date();
@Property({ type: 'text' })
name!: string;
@Property({ name: 'permissions', type: types.array })
roles: string[] = [];
}
export interface UserDTO {
id: string;
roles: string[];
createdAt: string;
}
export function formatUser(user: User): UserDTO {
return {
id: user.id,
roles: user.roles,
createdAt: user.createdAt.toISOString(),
};
}