User CRUD on backend and refactors

This commit is contained in:
2025-10-09 16:25:15 +02:00
parent 486ff6279d
commit 2f96b55205
7 changed files with 246 additions and 174 deletions

View File

@@ -22,5 +22,5 @@ export type RepertoireId = typeof RepertoireId.Type;
export const RequestId = pipe(Schema.UUID, Schema.brand("RequestId"));
export type RequestId = typeof RequestId.Type;
export const UserId = pipe(Schema.UUID, Schema.brand("UserId"));
export const UserId = pipe(Schema.String, Schema.brand("UserId"));
export type UserId = typeof UserId.Type;

View File

@@ -8,6 +8,7 @@ import * as Api from "./Api";
export enum Role {
Viewer = "Viewer",
Editor = "Editor",
Admin = "Admin",
}
export const SystemInformation = Schema.Struct({
@@ -78,6 +79,16 @@ export const User = Schema.Struct({
roles: Schema.HashSet(Schema.Enums(Role)),
});
export const User_Query = Schema.Struct({
displayName: pipe(Schema.NonEmptyString, Schema.optionalWith({ as: "Option", exact: true })),
role: pipe(Schema.Enums(Role), Schema.optionalWith({ as: "Option", exact: true })),
}).pipe(Schema.extend(Pagination));
export const User_AssignRoles = Schema.Struct({
userId: UserId,
roles: Schema.HashSet(Schema.Enums(Role)),
});
export type Attachment = typeof Attachment.Type;
export type Piece = typeof Piece.Type;
export type Piece_Create = typeof Piece_Create.Type;
@@ -85,6 +96,7 @@ export type Piece_Query = typeof Piece_Query.Type;
export type Repertoire = typeof Repertoire.Type;
export type Repertoire_Query = typeof Repertoire_Query.Type;
export type User = typeof User.Type;
export type User_AssignRoles = typeof User_AssignRoles.Type;
// --- MARK: ERROR TYPES -------------------------------------------------------
@@ -102,11 +114,29 @@ export default Api.bundle({
me: Api.make(Schema.Void, User, Unauthenticated),
logout: Api.make(Schema.Void, Schema.Void),
// --- User CRUD ---
getUser: Api.make(
UserId,
User,
Schema.Union(Unauthenticated, NotFound),
),
queryUsers: Api.make(
User_Query,
pipe(UserId, Schema.Array),
Schema.Union(Unauthenticated),
),
updateUser: Api.make(
User_AssignRoles,
User,
Schema.Union(Unauthenticated, Unauthorized, NotFound),
),
deleteUser: Api.make(
UserId,
Schema.Void,
Schema.Union(Unauthenticated, Unauthorized, NotFound),
),
// --- Piece CRUD ---
@@ -183,7 +213,7 @@ export default Api.bundle({
Repertoire,
Schema.Union(Unauthenticated, Unauthorized, NotFound),
),
queryRepertoire: Api.make(
queryRepertoires: Api.make(
Repertoire_Query,
pipe(RepertoireId, Schema.Array),
Schema.Union(Unauthenticated, Unauthorized),