From c9a1b8ceeabeaf271ed70b2558ddc948b449e82b Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Thu, 23 May 2024 19:52:43 +0200 Subject: [PATCH] chore(notifications): remove old unsed code --- .../main/typescript/api/messages/channel.ts | 107 ----- .../main/typescript/api/messages/direct.ts | 90 ----- .../main/typescript/api/monitoring/status.ts | 37 -- .../main/typescript/api/multimedia/session.ts | 120 ------ .../main/typescript/api/piperchat/channel.ts | 270 ------------- .../main/typescript/api/piperchat/server.ts | 370 ------------------ .../src/main/typescript/api/users/auth.ts | 192 --------- .../src/main/typescript/api/users/friends.ts | 132 ------- .../src/main/typescript/api/users/profile.ts | 71 ---- .../src/main/typescript/api/users/user.ts | 106 ----- .../main/typescript/events-configuration.ts | 16 +- .../repositories/notification-repository.ts | 24 -- 12 files changed, 2 insertions(+), 1533 deletions(-) delete mode 100644 notifications-service/src/main/typescript/api/messages/channel.ts delete mode 100644 notifications-service/src/main/typescript/api/messages/direct.ts delete mode 100644 notifications-service/src/main/typescript/api/monitoring/status.ts delete mode 100644 notifications-service/src/main/typescript/api/multimedia/session.ts delete mode 100644 notifications-service/src/main/typescript/api/piperchat/channel.ts delete mode 100644 notifications-service/src/main/typescript/api/piperchat/server.ts delete mode 100644 notifications-service/src/main/typescript/api/users/auth.ts delete mode 100644 notifications-service/src/main/typescript/api/users/friends.ts delete mode 100644 notifications-service/src/main/typescript/api/users/profile.ts delete mode 100644 notifications-service/src/main/typescript/repositories/notification-repository.ts diff --git a/notifications-service/src/main/typescript/api/messages/channel.ts b/notifications-service/src/main/typescript/api/messages/channel.ts deleted file mode 100644 index 9b63a2a44..000000000 --- a/notifications-service/src/main/typescript/api/messages/channel.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { Empty, ErrorResponse, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ -export module GetChannelMessagesApi { - export module Request { - export type Type = Body & Params & Query; - export type Params = { - serverId: string; - channelId: string; - }; - export type Body = Empty; - export type Query = { - from: number; - limit: number; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: {}, - Query: { - from: "number", - limit: "number", - }, - }; - } - export module Responses { - export interface Message { - _id: string; - sender: string; - content: string; - timestamp: Date; - } - export class Success extends Response { - statusCode = 200; - message = "Messages retrieved successfully"; - constructor(public messages: Message[]) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class ChannelNotFound extends ErrorResponse { - statusCode = 404; - error = "Channel not found" as const; - } - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - - export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module SendMessageInChannelApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - channelId: string; - }; - export type Body = { - content: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: { - content: "string", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Message sent successfully"; - } - export type Type = Success; - } - export module Errors { - export class ChannelNotFound extends ErrorResponse { - statusCode = 404; - error = "Channel not found" as const; - } - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ChannelNotFound | ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/messages/direct.ts b/notifications-service/src/main/typescript/api/messages/direct.ts deleted file mode 100644 index e21d014eb..000000000 --- a/notifications-service/src/main/typescript/api/messages/direct.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Empty, ErrorResponse, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ -export module GetDirectMessagesApi { - export module Request { - export type Type = Body & Params & Query; - export type Params = { - username: string; - }; - export type Body = Empty; - export type Query = { - from: number; - limit: number; - }; - export const Schema: RequestSchema = { - Params: { - username: "string", - }, - Body: {}, - Query: { - from: "number", - limit: "number", - }, - }; - } - export module Responses { - export interface Message { - _id: string; - sender: string; - content: string; - timestamp: Date; - } - export class Success extends Response { - statusCode = 200; - message = "Messages retrieved successfully"; - constructor(public messages: Message[]) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class DirectNotFound extends ErrorResponse { - statusCode = 404; - error = "Direct not found" as const; - } - export type Type = DirectNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -export module SendDirectMessageApi { - export module Request { - export type Type = Body & Params; - export type Params = { - username: string; - }; - export type Body = { - message: string; - }; - export type Query = Empty; - export const Schema: RequestSchema = { - Params: { - username: "string", - }, - Body: { - message: "string", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Message sent successfully"; - } - export type Type = Success; - } - export module Errors { - export class DirectNotFound extends ErrorResponse { - statusCode = 404; - error = "Direct not found" as const; - } - export class CannotSendDirectMessageToYourself extends ErrorResponse { - statusCode = 400; - error = "Cannot send direct message to yourself" as const; - } - export type Type = DirectNotFound | CannotSendDirectMessageToYourself; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/monitoring/status.ts b/notifications-service/src/main/typescript/api/monitoring/status.ts deleted file mode 100644 index f0e3e3a9c..000000000 --- a/notifications-service/src/main/typescript/api/monitoring/status.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Empty, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ - -export module GetServicesStatusApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: {}, - Body: {}, - }; - } - - export module Responses { - interface ServiceStatus { - _id: string; - service: string; - status: string; - timestamp: Date; - } - export class Success extends Response { - statusCode = 200; - services: ServiceStatus[]; - constructor(services: ServiceStatus[]) { - super(); - this.services = services; - } - } - export type Type = Success; - } - export module Errors { - export type Type = Empty; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/multimedia/session.ts b/notifications-service/src/main/typescript/api/multimedia/session.ts deleted file mode 100644 index 033910bb9..000000000 --- a/notifications-service/src/main/typescript/api/multimedia/session.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ - -export module GetChannelSessionIdApi { - export module Request { - export type Type = Params; - export type Params = { - serverId: string; - channelId: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Session id retrieved successfully" as const; - sessionId: string; - constructor(data: { sessionId: string }) { - super(); - this.sessionId = data.sessionId; - } - } - export type Type = Success; - } - export module Errors { - export class ChannelNotFound extends Response { - statusCode = 404; - message = "Channel not found" as const; - } - export class UserNotAuthorized extends Response { - statusCode = 403; - message = "User not authorized" as const; - } - export type Type = ChannelNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetDirectSessionIdApi { - export module Request { - export type Type = Params; - export type Params = { - username: string; - }; - export const Schema: RequestSchema = { - Params: { - username: "string", - }, - Body: {}, - }; - } - - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Session id retrieved successfully" as const; - sessionId: string; - constructor(data: { sessionId: string }) { - super(); - this.sessionId = data.sessionId; - } - } - export type Type = Success; - } - - export module Errors { - export class FriendshipNotFound extends Response { - statusCode = 404; - message = "Friendship not found" as const; - } - export type Type = FriendshipNotFound; - } - - export type Response = Responses.Type | Errors.Type; -} - -export module GetUsersInSession { - export module Request { - export type Type = Params; - export type Params = { - sessionId: string; - }; - export const Schema: RequestSchema = { - Params: { - sessionId: "string", - }, - Body: {}, - }; - } - - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Users retrieved successfully" as const; - users: string[]; - constructor(data: { users: string[] }) { - super(); - this.users = data.users; - } - } - export type Type = Success; - } - - export module Errors { - export class SessionNotFound extends Response { - statusCode = 404; - message = "Session not found" as const; - } - export type Type = SessionNotFound; - } - - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/piperchat/channel.ts b/notifications-service/src/main/typescript/api/piperchat/channel.ts deleted file mode 100644 index 778f2f99d..000000000 --- a/notifications-service/src/main/typescript/api/piperchat/channel.ts +++ /dev/null @@ -1,270 +0,0 @@ -import { Empty, ErrorResponse, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ -export module GetChannelsApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - interface Channel { - id: string; - name: string; - createdAt: Date; - channelType: string; - description?: string; - } - export class Success extends Response { - statusCode = 200; - message = "Channels retrieved successfully"; - constructor(public channels: Channel[]) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetChannelByIdApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - channelId: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: {}, - }; - } - export module Responses { - export interface Channel { - id: string; - name: string; - createdAt: Date; - channelType: string; - description?: string; - } - export class Success extends Response { - statusCode = 200; - message = "Channels retrieved successfully"; - constructor(public channel: Channel) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class ChannelNotFound extends ErrorResponse { - statusCode = 404; - error = "Channel not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - - export type Type = ChannelNotFound | UserNotAuthorized | ServerNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -export module CreateChannelApi { - export enum ChannelType { - Messages = "messages", - Multimedia = "multimedia", - } - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - }; - export type Body = { - name: string; - channelType: ChannelType; - description?: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: { - name: "string", - channelType: "string", - description: "string?", - }, - }; - } - export module Responses { - interface Channel { - id: string; - name: string; - createdAt: Date; - channelType: string; - description?: string; - } - export class Success extends Response { - statusCode = 200; - message = "Channel created successfully"; - channel: Channel; - constructor(channel: Channel) { - super(); - this.channel = channel; - } - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - - export class ChannelAlreadyExists extends ErrorResponse { - statusCode = 409; - error = "Channel already exists" as const; - } - - export class InvalidChannelType extends ErrorResponse { - statusCode = 400; - error = "Invalid channel type" as const; - } - - export type Type = - | ServerNotFound - | UserNotAuthorized - | ChannelAlreadyExists - | InvalidChannelType; - } - export type Response = Responses.Type | Errors.Type; -} - -export module UpdateChannelApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - channelId: string; - }; - export type Body = { - name?: string; - description?: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: { - name: "string?", - description: "string?", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Channel updated successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class ChannelNotFound extends ErrorResponse { - statusCode = 404; - error = "Channel not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - - export class ChannelAlreadyExists extends ErrorResponse { - statusCode = 409; - error = "Channel already exists" as const; - } - export type Type = - | ServerNotFound - | ChannelNotFound - | UserNotAuthorized - | ChannelAlreadyExists; - } - export type Response = Responses.Type | Errors.Type; -} - -export module DeleteChannelApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - channelId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - channelId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Channel deleted successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class ChannelNotFound extends ErrorResponse { - statusCode = 404; - error = "Channel not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ServerNotFound | ChannelNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/piperchat/server.ts b/notifications-service/src/main/typescript/api/piperchat/server.ts deleted file mode 100644 index c67a12604..000000000 --- a/notifications-service/src/main/typescript/api/piperchat/server.ts +++ /dev/null @@ -1,370 +0,0 @@ -import { Empty, ErrorResponse, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ -export module KickUserFromServerApi { - export module Request { - export type Type = Params & Body; - export type Params = { - serverId: string; - username: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - username: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "User kicked successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server or user not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export class OwnerCannotLeave extends ErrorResponse { - statusCode = 405; - error = "Owner cannot leave the server" as const; - } - export type Type = ServerNotFound | UserNotAuthorized | OwnerCannotLeave; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetServerParticipantsApi { - export module Request { - export type Type = Params & Body; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - constructor(public participants: string[]) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module JoinServerApi { - export module Request { - export type Type = Params & Body; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Server joined successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserAlreadyJoined extends ErrorResponse { - statusCode = 403; - error = "User already joined" as const; - } - export type Type = ServerNotFound | UserAlreadyJoined; - } - export type Response = Responses.Type | Errors.Type; -} - -export module LeaveServerApi { - export module Request { - export type Type = Params & Body; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Server left successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotInServer extends ErrorResponse { - statusCode = 403; - error = "User not in server" as const; - } - export class OwnerCannotLeave extends ErrorResponse { - statusCode = 422; - error = "Owner cannot leave the server" as const; - } - export type Type = ServerNotFound | UserNotInServer | OwnerCannotLeave; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetServerApi { - export module Request { - export type Type = Params & Body; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - export interface Channel { - id: string; - name: string; - createdAt: Date; - channelType: string; - description?: string; - } - export interface Server { - id: string; - name: string; - description: string; - owner: string; - participants: string[]; - createdAt: Date; - channels: Channel[]; - } - export class Success extends Response { - statusCode = 200; - constructor(public server: Server) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module UpdateServerApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - }; - export type Body = { - name?: string; - description?: string; - }; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: { - name: "string?", - description: "string?", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Server updated successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export class NameOrDescriptionRequired extends ErrorResponse { - statusCode = 422; - error = "Name or description required" as const; - } - export type Type = ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module DeleteServerApi { - export module Request { - export type Type = Body & Params; - export type Params = { - serverId: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - serverId: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Server deleted successfully"; - } - export type Type = Success; - } - export module Errors { - export class ServerNotFound extends ErrorResponse { - statusCode = 404; - error = "Server not found" as const; - } - export class UserNotAuthorized extends ErrorResponse { - statusCode = 403; - error = "User not authorized" as const; - } - export type Type = ServerNotFound | UserNotAuthorized; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetServersApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: {}, - Body: {}, - }; - } - export module Responses { - export interface Channel { - id: string; - name: string; - createdAt: Date; - channelType: string; - description?: string; - } - export interface Server { - id: string; - name: string; - description: string; - owner: string; - participants: string[]; - createdAt: Date; - channels: Channel[]; - } - export class Success extends Response { - statusCode = 200; - constructor(public servers: Server[]) { - super(); - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -export module CreateServerApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = { - name: string; - description: string; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - name: "string", - description: "string", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Server created successfully"; - serverId: string; - constructor(serverId: string) { - super(); - this.serverId = serverId; - } - } - export type Type = Success; - } - export module Errors { - export class NameOrDescriptionRequired extends ErrorResponse { - statusCode = 422; - error = "Name or description required" as const; - } - export type Type = NameOrDescriptionRequired; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/users/auth.ts b/notifications-service/src/main/typescript/api/users/auth.ts deleted file mode 100644 index b8b467bdb..000000000 --- a/notifications-service/src/main/typescript/api/users/auth.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { Empty, ErrorResponse, Response, ResponseFacade } from "../response"; -import { RequestSchema, EmptySchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ -/** - * Register endpoint - */ -export module RegisterApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = { - username: string; - password: string; - email?: string; - description?: string; - photo?: { - data: Buffer; - contentType: string; - }; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - username: "string", - password: "string", - email: "string?", - description: "string?", - photo: "Buffer?", - }, - }; - } - - export module Responses { - interface UserLoginResponse { - username: string; - email?: string; - description?: string; - photo?: { - data: Buffer; - contentType: string; - }; - } - - export class Success extends Response { - statusCode = 200; - createdUser: UserLoginResponse; - constructor(user: UserLoginResponse) { - super(); - this.createdUser = user; - } - } - - export type Type = Success; - } - - export module Errors { - export class UserAlreadyExists extends ErrorResponse { - statusCode = 409; - error = "User already exists" as const; - } - - export class EmailAlreadyExists extends ErrorResponse { - statusCode = 409; - error = "Email already exists" as const; - } - - export type Type = UserAlreadyExists | EmailAlreadyExists; - } - - export type Response = Responses.Type | Errors.Type; -} - -/** - * Login endpoint - */ -export module LoginApi { - export module Request { - export type Type = Body & Params; - export type Params = Record; - export type Body = { - username: string; - password: string; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - username: "string", - password: "string", - }, - }; - } - - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Logged in" as const; - jwt: string; - constructor(jwt: string) { - super(); - this.jwt = jwt; - } - override send(res: ResponseFacade) { - res.cookie("jwt", this.jwt, { httpOnly: true }); - super.send(res); - } - } - - export type Type = Success; - } - - export module Errors { - export class UsernameOrPasswordIncorrect extends ErrorResponse { - statusCode = 401; - error = "Username or password incorrect" as const; - } - export type Type = UsernameOrPasswordIncorrect; - } - - export type Response = Responses.Type | Errors.Type; -} - -/** - * Logout endpoint - */ -export module LogoutApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema = EmptySchema; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Logged out" as const; - override send(res: ResponseFacade) { - res.clearCookie("jwt"); - super.send(res); - } - } - - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -/** - * Refresh token endpoint - */ -export module RefreshTokenApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema = EmptySchema; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Refreshed token" as const; - jwt: string; - constructor(jwt: string) { - super(); - this.jwt = jwt; - } - override send(res: ResponseFacade) { - res.cookie("jwt", this.jwt, { httpOnly: true }); - super.send(res); - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export class InvalidRefreshToken extends ErrorResponse { - statusCode = 401; - error = "Refresh token is missing or invalid" as const; - } - export type Type = UserNotFound | InvalidRefreshToken; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/users/friends.ts b/notifications-service/src/main/typescript/api/users/friends.ts deleted file mode 100644 index 61bb476ec..000000000 --- a/notifications-service/src/main/typescript/api/users/friends.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { Empty, ErrorResponse, Response } from "../response"; -import { EmptySchema, RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ - -export module GetFriendsApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema: RequestSchema = EmptySchema; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - friends: string[]; - constructor(friends: string[]) { - super(); - this.friends = friends; - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -export module GetFriendsRequestsApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema: RequestSchema = EmptySchema; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - requests: string[]; - constructor(requests: string[]) { - super(); - this.requests = requests; - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -export module SendFriendRequestApi { - export module Request { - export type Type = Body & Params; - export enum FriendRequestAction { - send = "send", - accept = "accept", - deny = "deny", - } - export type Params = Empty; - export type Body = { - to: string; - action: FriendRequestAction; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - to: "string", - action: "string", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Friend request sent" as const; - } - export class FriendRequestAccepted extends Response { - statusCode = 200; - message = "Friend request accepted" as const; - } - export class FriendRequestDenied extends Response { - statusCode = 200; - message = "Friend request denied" as const; - } - - export type Type = Success | FriendRequestAccepted | FriendRequestDenied; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export class InvalidAction extends ErrorResponse { - statusCode = 400; - error: string; - constructor(action: string) { - super(); - this.error = `Invalid 'action' parameter in body: '${action}'`; - } - } - export class FriendRequestAlreadySent extends ErrorResponse { - statusCode = 409; - error = "Friend request already sent" as const; - } - export class FriendRequestNotFound extends ErrorResponse { - statusCode = 404; - error = "Friend request not found" as const; - } - export class CannotSendFriendRequestToYourself extends ErrorResponse { - statusCode = 400; - error = "Cannot send a friend request to yourself" as const; - } - - export type Type = - | UserNotFound - | InvalidAction - | FriendRequestAlreadySent - | FriendRequestNotFound - | CannotSendFriendRequestToYourself; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/users/profile.ts b/notifications-service/src/main/typescript/api/users/profile.ts deleted file mode 100644 index 8f2dafef0..000000000 --- a/notifications-service/src/main/typescript/api/users/profile.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { Empty, Response } from "../response"; -import { RequestSchema } from "../schema"; -/* eslint-disable @typescript-eslint/no-namespace */ - -/** - * Update photo endpoint - */ -export module UpdatePhotoApi { - export type Photo = { - data: Buffer; - contentType: string; - }; - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = { - photo: Photo; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - photo: "Photo", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Photo updated successfully" as const; - } - export type Type = Success; - } - export module Errors { - export class InvalidPhoto extends Response { - statusCode = 400; - message = "Invalid photo" as const; - } - export type Type = InvalidPhoto; - } - export type Response = Responses.Type | Errors.Type; -} - -/** - * Update description endpoint - */ -export module UpdateDescriptionApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = { - description: string; - }; - export const Schema: RequestSchema = { - Params: {}, - Body: { - description: "string", - }, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - message = "Description updated successfully" as const; - } - export type Type = Success; - } - export module Errors { - export type Type = Empty; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/api/users/user.ts b/notifications-service/src/main/typescript/api/users/user.ts index 094537df7..2e08fc7b9 100644 --- a/notifications-service/src/main/typescript/api/users/user.ts +++ b/notifications-service/src/main/typescript/api/users/user.ts @@ -1,36 +1,6 @@ /* eslint-disable @typescript-eslint/no-namespace */ import { Empty, ErrorResponse, Response } from "../response"; import { EmptySchema, RequestSchema } from "../schema"; -import { UpdatePhotoApi } from "./profile"; - -/** - * Whoami endpoint - */ -export module WhoamiApi { - export module Request { - export type Type = Body & Params; - export type Params = Empty; - export type Body = Empty; - export const Schema: RequestSchema = EmptySchema; - } - export module Responses { - interface WhoamiUser { - username: string; - email: string; - } - - export class Success extends Response { - statusCode = 200; - user: WhoamiUser; - constructor(user: WhoamiUser) { - super(); - this.user = user; - } - } - export type Type = Success; - } - export type Response = Responses.Type; -} /** * Get user status @@ -75,79 +45,3 @@ export module GetUserStatusApi { } export type Response = Responses.Type | Errors.Type; } - -/** - * Get user photo - */ -export module GetUserPhotoApi { - export module Request { - export type Type = Body & Params; - export type Params = { - username: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - username: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - photo: UpdatePhotoApi.Photo; - constructor(photo: UpdatePhotoApi.Photo) { - super(); - this.photo = photo; - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} - -/** - * Get user description - */ -export module GetUserDescriptionApi { - export module Request { - export type Type = Body & Params; - export type Params = { - username: string; - }; - export type Body = Empty; - export const Schema: RequestSchema = { - Params: { - username: "string", - }, - Body: {}, - }; - } - export module Responses { - export class Success extends Response { - statusCode = 200; - description: string; - constructor(description: string) { - super(); - this.description = description; - } - } - export type Type = Success; - } - export module Errors { - export class UserNotFound extends ErrorResponse { - statusCode = 404; - error = "User not found" as const; - } - export type Type = UserNotFound; - } - export type Response = Responses.Type | Errors.Type; -} diff --git a/notifications-service/src/main/typescript/events-configuration.ts b/notifications-service/src/main/typescript/events-configuration.ts index 6ee308361..0c314c1ff 100644 --- a/notifications-service/src/main/typescript/events-configuration.ts +++ b/notifications-service/src/main/typescript/events-configuration.ts @@ -41,17 +41,15 @@ import { UserKickedFromServerMessage, UserLeftServerMessage, } from "./messages-api/servers"; -import { piperkt } from "./events-lib"; -import ServerUserAddedEvent = piperkt.events.ServerUserAddedEvent; export class NotificationsServiceEventsConfiguration extends EventsConfiguration { constructor() { super(); - // this.listenToServersUpdates(); + this.listenToServersUpdates(); this.listenToFriendsRequest(); this.listenToMessages(); this.listenToUserStatus(); - // this.listenToChannelsUpdates(); + this.listenToChannelsUpdates(); } listenToUserStatus() { @@ -62,16 +60,6 @@ export class NotificationsServiceEventsConfiguration extends EventsConfiguration }); }); - // this.on(UserDeletedMessage, async (event: UserDeletedMessage) => { - // const user = await Users.findOne({ username: event.username }); - // const friends = user?.friends; - // await Users.deleteOne({ username: event.username }); - // await Users.updateMany( - // { username: { $in: friends } }, - // { $pull: { friends: event.username } } - // ); - // }); - this.on(UserOnlineMessage, async (event: UserOnlineMessage) => { const user = await Users.findOne({ username: event.username }); const friends = user?.friends; diff --git a/notifications-service/src/main/typescript/repositories/notification-repository.ts b/notifications-service/src/main/typescript/repositories/notification-repository.ts deleted file mode 100644 index 172129f06..000000000 --- a/notifications-service/src/main/typescript/repositories/notification-repository.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { notifiableUsers } from "../models/notification-model"; - -export interface Message { - from: string; - to: string; - content: string; -} - -export interface NotificationRepository { - /** - * Perform operation on new message arrived. - * @param message The message arrived. - */ - onNewMessage(message: Message): void; -} - -export class NotificationRepositoryImpl implements NotificationRepository { - onNewMessage(message: Message): void { - notifiableUsers.sendIfPresent(message.to, { - from: message.from, - content: message.content, - }); - } -}