Refactor part 2

This commit is contained in:
Aslan 2026-01-07 17:13:56 -05:00
parent e21a807fb3
commit 80196b732a
9 changed files with 78 additions and 25 deletions

View file

@ -84,6 +84,7 @@ const postCreateCommunity = async (
name: community.name,
description: community.description,
ownerId: community.ownerId,
creationDate: community.creationDate.getTime(),
} as IPostCreateCommunityResponseSuccess;
};
@ -116,6 +117,8 @@ const patchCommunity = async (request: FastifyRequest, reply: FastifyReply) => {
id: community.id,
name: community.name,
description: community.description,
ownerId: community.ownerId,
creationDate: community.creationDate.getTime(),
} as IPatchCommunityResponseSuccess;
};

View file

@ -1,15 +1,6 @@
import type { API_ERROR } from "../errors.js";
interface IGetInviteParams {
id: string;
}
interface IGetInviteResponseError {
id: string;
error: API_ERROR;
}
interface IGetInviteResponseSuccess {
interface IInvite {
id: string;
communityId: string;
valid: boolean;
@ -21,6 +12,17 @@ interface IGetInviteResponseSuccess {
expirationDate: number;
}
interface IGetInviteParams {
id: string;
}
interface IGetInviteResponseError {
id: string;
error: API_ERROR;
}
interface IGetInviteResponseSuccess extends IInvite {}
interface IDeleteInviteParams {
id: string;
}
@ -53,6 +55,7 @@ interface IPostAcceptDeleteInviteResponseSuccess {
}
export {
type IInvite,
type IGetInviteParams,
type IGetInviteResponseError,
type IGetInviteResponseSuccess,

View file

@ -55,7 +55,9 @@ const getRole = async (request: FastifyRequest, reply: FastifyReply) => {
return {
id: role.id,
name: role.name,
description: role.description,
communityId: role.communityId,
permissions: role.permissions,
creationDate: role.creationDate.getTime(),
} as IGetRoleResponseSuccess;
};
@ -75,7 +77,10 @@ const postCreateRole = async (request: FastifyRequest, reply: FastifyReply) => {
return {
id: role.id,
name: role.name,
description: role.description,
communityId: role.communityId,
permissions: role.permissions,
creationDate: role.creationDate.getTime(),
} as IPostCreateRoleResponseSuccess;
};
@ -103,8 +108,10 @@ const patchRole = async (request: FastifyRequest, reply: FastifyReply) => {
return {
id: role.id,
name: role.name,
description: role.description,
communityId: role.communityId,
permissions: role.permissions,
creationDate: role.creationDate.getTime(),
} as IPatchRoleResponseSuccess;
};

View file

@ -78,7 +78,12 @@ interface IPostAssignRoleResponseError {
error: API_ERROR;
}
interface IPostAssignRoleResponseSuccess extends IRole {}
interface IPostAssignRoleResponseSuccess {
id: string;
name: string;
communityId: string;
userId: string;
}
interface IPostUnassignRoleParams {
id: string;
@ -93,7 +98,12 @@ interface IPostUnassignRoleResponseError {
error: API_ERROR;
}
interface IPostUnassignRoleResponseSuccess extends IRole {}
interface IPostUnassignRoleResponseSuccess {
id: string;
name: string;
communityId: string;
userId: string;
}
export {
type IRole,

View file

@ -1,5 +1,11 @@
import type { API_ERROR } from "../errors.js";
interface ISession {
id: string;
userId: string;
creationDate: number;
}
interface IGetSessionParams {
id: string;
}
@ -9,11 +15,7 @@ interface IGetSessionResponseError {
error: API_ERROR;
}
interface IGetSessionResponseSuccess {
id: string;
userId: string;
creationDate: number;
}
interface IGetSessionResponseSuccess extends ISession {}
interface IDeleteSessionParams {
id: string;
@ -30,6 +32,7 @@ interface IDeleteSessionResponseSuccess {
}
export {
type ISession,
type IGetSessionParams,
type IGetSessionResponseError,
type IGetSessionResponseSuccess,

View file

@ -98,6 +98,8 @@ const postCreateUser = async (request: FastifyRequest, reply: FastifyReply) => {
email: user.email,
description: user.description,
admin: user.admin,
registerDate: user.registerDate.getTime(),
lastLogin: user.lastLogin?.getTime() ?? 0,
} as IPostCreateUserResponseSuccess;
};
@ -124,8 +126,12 @@ const patchUser = async (request: FastifyRequest, reply: FastifyReply) => {
return {
id: user.id,
username: user.username,
email: user.email,
description: user.description,
admin: user.admin,
registerDate: user.registerDate.getTime(),
lastLogin: user.lastLogin?.getTime() ?? 0,
} as IPatchUserResponseSuccess;
};