mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 18:13:26 +00:00
add basic repo setup, with user creation
This commit is contained in:
31
src/db/models/User.ts
Normal file
31
src/db/models/User.ts
Normal 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(),
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user