diff --git a/package.json b/package.json index ade185a..b2e0e89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tether", - "version": "0.3.5", + "version": "0.3.6", "description": "Communication server using the Nexlink protocol", "repository": { "type": "git", diff --git a/prisma/migrations/20260103133742_description_role_channel/migration.sql b/prisma/migrations/20260103133742_description_role_channel/migration.sql new file mode 100644 index 0000000..96fcfff --- /dev/null +++ b/prisma/migrations/20260103133742_description_role_channel/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Channel" ADD COLUMN "description" TEXT; + +-- AlterTable +ALTER TABLE "Role" ADD COLUMN "description" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c9028c6..c146af8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -24,6 +24,7 @@ model Community { model Channel { id String @id @unique @default(uuid()) name String + description String? community Community @relation(fields: [communityId], references: [id], onDelete: Cascade) communityId String creationDate DateTime @default(now()) @@ -32,6 +33,7 @@ model Channel { model Role { id String @id @unique @default(uuid()) name String + description String? community Community @relation(fields: [communityId], references: [id], onDelete: Cascade) communityId String users User[] @relation(name: "UsersRolesToUsers") diff --git a/src/controllers/channel/channel.ts b/src/controllers/channel/channel.ts index fc1e6c5..1229415 100644 --- a/src/controllers/channel/channel.ts +++ b/src/controllers/channel/channel.ts @@ -45,6 +45,7 @@ const getChannel = async (request: FastifyRequest, reply: FastifyReply) => { return { id: channel.id, name: channel.name, + description: channel.description, communityId: channel.communityId, creationDate: channel.creationDate.getTime(), } as IGetChannelResponseSuccess; @@ -68,7 +69,9 @@ const postCreateChannel = async ( return { id: channel.id, name: channel.name, + description: channel.description, communityId: channel.communityId, + creationDate: channel.creationDate.getTime(), } as IPostCreateChannelResponseSuccess; }; @@ -100,7 +103,9 @@ const patchChannel = async (request: FastifyRequest, reply: FastifyReply) => { return { id: channel.id, name: channel.name, + description: channel.description, communityId: channel.communityId, + creationDate: channel.creationDate.getTime(), } as IPatchChannelResponseSuccess; }; diff --git a/src/controllers/channel/types.ts b/src/controllers/channel/types.ts index 05b488e..65688d3 100644 --- a/src/controllers/channel/types.ts +++ b/src/controllers/channel/types.ts @@ -1,5 +1,13 @@ import type { API_ERROR } from "../errors.js"; +interface IChannel { + id: string; + name: string; + description: string; + communityId: string; + creationDate: number; +} + interface IGetChannelParams { id: string; } @@ -9,15 +17,11 @@ interface IGetChannelResponseError { error: API_ERROR; } -interface IGetChannelResponseSuccess { - id: string; - name: string; - communityId: string; - creationDate: number; -} +interface IGetChannelResponseSuccess extends IChannel {} interface IPostCreateChannelRequest { name: string; + description?: string; communityId: string; } @@ -26,11 +30,7 @@ interface IPostCreateChannelResponseError { error: API_ERROR; } -interface IPostCreateChannelResponseSuccess { - id: string; - name: string; - communityId: string; -} +interface IPostCreateChannelResponseSuccess extends IChannel {} interface IPatchChannelParams { id: string; @@ -38,6 +38,7 @@ interface IPatchChannelParams { interface IPatchChannelRequest { name?: string; + description?: string; } interface IPatchChannelResponseError { @@ -45,11 +46,7 @@ interface IPatchChannelResponseError { error: API_ERROR; } -interface IPatchChannelResponseSuccess { - id: string; - name: string; - communityId: string; -} +interface IPatchChannelResponseSuccess extends IChannel {} interface IDeleteChannelParams { id: string; @@ -66,6 +63,7 @@ interface IDeleteChannelResponseSuccess { } export { + type IChannel, type IGetChannelParams, type IGetChannelResponseError, type IGetChannelResponseSuccess, diff --git a/src/controllers/community/types.ts b/src/controllers/community/types.ts index 4dcc910..d831387 100644 --- a/src/controllers/community/types.ts +++ b/src/controllers/community/types.ts @@ -1,5 +1,13 @@ import type { API_ERROR } from "../errors.js"; +interface ICommunity { + id: string; + name: string; + description: string; + ownerId: string; + creationDate: number; +} + interface IGetCommunityParams { id: string; } @@ -9,13 +17,7 @@ interface IGetCommunityResponseError { error: API_ERROR; } -interface IGetCommunityResponseSuccess { - id: string; - name: string; - description: string; - ownerId: string; - creationDate: number; -} +interface IGetCommunityResponseSuccess extends ICommunity {} interface IPostCreateCommunityRequest { name: string; @@ -27,12 +29,7 @@ interface IPostCreateCommunityResponseError { error: API_ERROR; } -interface IPostCreateCommunityResponseSuccess { - id: string; - name: string; - description: string; - ownerId: string; -} +interface IPostCreateCommunityResponseSuccess extends ICommunity {} interface IPatchCommunityParams { id: string; @@ -48,11 +45,7 @@ interface IPatchCommunityResponseError { error: API_ERROR; } -interface IPatchCommunityResponseSuccess { - id: string; - name: string; - description: string; -} +interface IPatchCommunityResponseSuccess extends ICommunity {} interface IDeleteCommunityParams { id: string; @@ -147,6 +140,7 @@ interface IPostCreateInviteResponseSuccess { } export { + type ICommunity, type IGetCommunityParams, type IGetCommunityResponseError, type IGetCommunityResponseSuccess, diff --git a/src/controllers/role/role.ts b/src/controllers/role/role.ts index 0a26d2e..7dc55e2 100644 --- a/src/controllers/role/role.ts +++ b/src/controllers/role/role.ts @@ -3,9 +3,6 @@ import type { IGetRoleParams, IGetRoleResponseError, IGetRoleResponseSuccess, - IGetRolePermissionsParams, - IGetRolePermissionsResponseError, - IGetRolePermissionsResponseSuccess, IPostCreateRoleRequest, IPostCreateRoleResponseError, IPostCreateRoleResponseSuccess, @@ -63,38 +60,6 @@ const getRole = async (request: FastifyRequest, reply: FastifyReply) => { } as IGetRoleResponseSuccess; }; -const getRolePermissions = async ( - request: FastifyRequest, - reply: FastifyReply, -) => { - const { id } = request.params as IGetRolePermissionsParams; - const authHeader = request.headers["authorization"]; - - const role = await getRoleByIdAuth(id, authHeader); - if (!role) { - reply.status(404); - return { - id: id, - error: API_ERROR.NOT_FOUND, - } as IGetRolePermissionsResponseError; - } - if (role === API_ERROR.ACCESS_DENIED) { - reply.status(403); - return { - id: id, - error: API_ERROR.ACCESS_DENIED, - } as IGetRolePermissionsResponseError; - } - - return { - id: role.id, - name: role.name, - communityId: role.communityId, - permissions: role.permissions, - creationDate: role.creationDate.getTime(), - } as IGetRolePermissionsResponseSuccess; -}; - const postCreateRole = async (request: FastifyRequest, reply: FastifyReply) => { const createRoleRequest = request.body as IPostCreateRoleRequest; const authHeader = request.headers["authorization"]; @@ -228,7 +193,6 @@ const postUnassignRole = async ( export { getRole, - getRolePermissions, patchRole, deleteRole, postCreateRole, diff --git a/src/controllers/role/routes.ts b/src/controllers/role/routes.ts index fa72d9e..2c0cca2 100644 --- a/src/controllers/role/routes.ts +++ b/src/controllers/role/routes.ts @@ -3,7 +3,6 @@ import * as controller from "./role.js"; const roleRoutes = async (fastify: FastifyInstance) => { fastify.get(`/:id`, controller.getRole); - fastify.get(`/:id/permissions`, controller.getRolePermissions); fastify.post(`/`, controller.postCreateRole); fastify.patch(`/:id`, controller.patchRole); fastify.delete(`/:id`, controller.deleteRole); diff --git a/src/controllers/role/types.ts b/src/controllers/role/types.ts index 3910958..498b875 100644 --- a/src/controllers/role/types.ts +++ b/src/controllers/role/types.ts @@ -1,6 +1,15 @@ import type { PERMISSION } from "../../services/auth/permission.js"; import type { API_ERROR } from "../errors.js"; +interface IRole { + id: string; + name: string; + description: string; + permissions: PERMISSION[]; + communityId: string; + creationDate: number; +} + interface IGetRoleParams { id: string; } @@ -10,32 +19,11 @@ interface IGetRoleResponseError { error: API_ERROR; } -interface IGetRoleResponseSuccess { - id: string; - name: string; - communityId: string; - creationDate: number; -} - -interface IGetRolePermissionsParams { - id: string; -} - -interface IGetRolePermissionsResponseError { - id: string; - error: API_ERROR; -} - -interface IGetRolePermissionsResponseSuccess { - id: string; - name: string; - communityId: string; - permissions: PERMISSION[]; - creationDate: number; -} +interface IGetRoleResponseSuccess extends IRole {} interface IPostCreateRoleRequest { name: string; + description?: string; communityId: string; permissions: PERMISSION[]; } @@ -45,11 +33,7 @@ interface IPostCreateRoleResponseError { error: API_ERROR; } -interface IPostCreateRoleResponseSuccess { - id: string; - name: string; - communityId: string; -} +interface IPostCreateRoleResponseSuccess extends IRole {} interface IPatchRoleParams { id: string; @@ -57,6 +41,7 @@ interface IPatchRoleParams { interface IPatchRoleRequest { name?: string; + description?: string; } interface IPatchRoleResponseError { @@ -64,12 +49,7 @@ interface IPatchRoleResponseError { error: API_ERROR; } -interface IPatchRoleResponseSuccess { - id: string; - name: string; - communityId: string; - permissions: PERMISSION[]; -} +interface IPatchRoleResponseSuccess extends IRole {} interface IDeleteRoleParams { id: string; @@ -98,12 +78,7 @@ interface IPostAssignRoleResponseError { error: API_ERROR; } -interface IPostAssignRoleResponseSuccess { - id: string; - name: string; - communityId: string; - userId: string; -} +interface IPostAssignRoleResponseSuccess extends IRole {} interface IPostUnassignRoleParams { id: string; @@ -118,20 +93,13 @@ interface IPostUnassignRoleResponseError { error: API_ERROR; } -interface IPostUnassignRoleResponseSuccess { - id: string; - name: string; - communityId: string; - userId: string; -} +interface IPostUnassignRoleResponseSuccess extends IRole {} export { + type IRole, type IGetRoleParams, type IGetRoleResponseError, type IGetRoleResponseSuccess, - type IGetRolePermissionsParams, - type IGetRolePermissionsResponseError, - type IGetRolePermissionsResponseSuccess, type IPostCreateRoleRequest, type IPostCreateRoleResponseError, type IPostCreateRoleResponseSuccess, diff --git a/src/controllers/user/types.ts b/src/controllers/user/types.ts index 374a273..d85a0fe 100644 --- a/src/controllers/user/types.ts +++ b/src/controllers/user/types.ts @@ -1,5 +1,15 @@ import type { API_ERROR } from "../errors.js"; +interface IUser { + id: string; + username: string; + email: string; + description: string; + admin: boolean; + registerDate: number; + lastLogin: number; +} + interface IGetLoggedUserResponseError { error: API_ERROR; } @@ -17,15 +27,7 @@ interface IGetUserResponseError { error: API_ERROR; } -interface IGetUserResponseSuccess { - id: string; - username: string; - email: string; - description: string; - admin: boolean; - registerDate: number; - lastLogin: number; -} +interface IGetUserResponseSuccess extends IUser {} interface IPostCreateUserRequest { username: string; @@ -40,13 +42,7 @@ interface IPostCreateUserResponseError { error: API_ERROR; } -interface IPostCreateUserResponseSuccess { - id: string; - username: string; - email: string; - description: string; - admin: boolean; -} +interface IPostCreateUserResponseSuccess extends IUser {} interface IPatchUserParams { id: string; @@ -62,11 +58,7 @@ interface IPatchUserResponseError { error: API_ERROR; } -interface IPatchUserResponseSuccess { - id: string; - email: string; - description: string; -} +interface IPatchUserResponseSuccess extends IUser {} interface IDeleteUserParams { id: string; @@ -121,6 +113,7 @@ interface IGetCommunitiesResponseCommunity { } export { + type IUser, type IGetLoggedUserResponseError, type IGetLoggedUserResponseSuccess, type IGetUserParams, diff --git a/tests/2.community.test.js b/tests/2.community.test.js index 1209248..052599f 100644 --- a/tests/2.community.test.js +++ b/tests/2.community.test.js @@ -279,10 +279,7 @@ test("can get roles", async () => { }); test("can get permissions", async () => { - const response = await apiGet( - `role/${state.roleId}/permissions`, - state.token2, - ); + const response = await apiGet(`role/${state.roleId}`, state.token2); assert.equal(response.id, state.roleId); assert.equal(response.name, state.roleName);