Flesh-out model on the backend

This commit is contained in:
Szymon Nowakowski
2024-12-26 21:40:05 +01:00
parent 8e57a76e60
commit 1d2b19f072
6 changed files with 460 additions and 113 deletions

View File

@@ -0,0 +1,109 @@
import * as Common from "common";
import * as Function from "common/Function";
import { t } from "elysia";
const brandedString = <T>() => t.Transform(t.String())
.Decode(Function.unsafeCoerce<string, T>)
.Encode(Function.unsafeCoerce<T, string>);
export const Sha256_Hex = brandedString<Common.Sha256_Hex>();
export const AttachmentId = brandedString<Common.AttachmentId>();
export const PieceId = brandedString<Common.PieceId>();
export const RepertoireId = brandedString<Common.RepertoireId>();
export const RequestId = brandedString<Common.RequestId>();
export const SessionId = brandedString<Common.SessionId>();
export const UserId = brandedString<Common.UserId>();
const SystemInformation = Object.freeze({
createdBy: t.Nullable(UserId),
createdAt: t.String(),
modifiedBy: t.Nullable(UserId),
modifiedAt: t.Nullable(t.String()),
});
const Pagination = Object.freeze({
offset: t.Optional(t.Integer({ minimum: 0 })),
limit: t.Optional(t.Integer({ minimum: 1, maximum: 100 })),
});
export const AccessLog = t.Object({
requestId: RequestId,
timestamp: t.String(),
method: t.String(),
pathname: t.String(),
query: t.String(),
ip: t.Nullable(t.String()),
});
export const Attachment = t.Object({
attachmentId: AttachmentId,
pieceId: PieceId,
filename: t.String(),
sha256: Sha256_Hex,
mediaType: t.String(),
...SystemInformation,
});
export const Piece = t.Object({
pieceId: PieceId,
name: t.String({ minLength: 1 }),
composer: t.Nullable(t.String({ minLength: 1 })),
lyricist: t.Nullable(t.String({ minLength: 1 })),
arranger: t.Nullable(t.String({ minLength: 1 })),
attachments: t.Array(Attachment),
...SystemInformation,
});
export const Piece_Post = t.Object({
name: t.String({ minLength: 1 }),
composer: t.Nullable(t.String({ minLength: 1 })),
lyricist: t.Nullable(t.String({ minLength: 1 })),
arranger: t.Nullable(t.String({ minLength: 1 })),
});
export const Piece_Query = t.Object({
name: t.Optional(t.String()),
author: t.Optional(t.String()),
...Pagination,
});
export const Repertoire = t.Object({
repertoireId: RepertoireId,
name: t.String(),
entries: t.Array(PieceId),
...SystemInformation,
});
export const User = t.Object({
userId: UserId,
username: t.String(),
admin: t.Boolean(),
});
export const User_Patch = t.Object({
username: t.Optional(t.String()),
password: t.Optional(t.String({ minLength: 8 })),
admin: t.Optional(t.Boolean()),
});
export const User_Post = t.Object({
username: t.String(),
password: t.String({ minLength: 8 }),
admin: t.Boolean(),
});
export const User_Query = t.Object({
username: t.Optional(t.String()),
...Pagination,
});
export type AccessLog = typeof AccessLog.static;
export type Attachment = typeof Attachment.static;
export type Piece = typeof Piece.static;
export type Piece_Post = typeof Piece_Post.static;
export type Piece_Query = typeof Piece_Query.static;
export type Repertoire = typeof Repertoire.static;
export type User = typeof User.static;
export type User_Patch = typeof User_Patch.static;
export type User_Post = typeof User_Post.static;
export type User_Query = typeof User_Query.static;