Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: separate server related code #585

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useApp } from '@/context/AppContext';
import useChatUtils from '@/lib/chatSocket';
import MessageStatus from '@/components/Chat/MessageStatus';
import { useNotification } from '@/lib/notification';
import events from '@/constants';
import events from '@/shared/constants/constants';
import { createBrowserNotification } from '@/lib/browserNotification';

import chatHelper, { adjustTextareaHeight, getTime } from '../lib/chatHelper';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Chat/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon } from '@iconify/react';

import EmojiPicker from './EmojiPicker';
import useKeyPress, { ShortcutFlags } from '@/hooks/useKeyPress';
import events from '@/constants';
import events from '@/shared/constants/constants';

import { useSocket } from '@/context/SocketContext';
import { useChat } from '@/context/ChatContext';
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useSocket } from '@/context/SocketContext';
import { useApp } from '@/context/AppContext';

// Lib
import constants from '@/constants';
import constants from '@/shared/constants/constants';
import { IsActiveType } from '@/types/types';
import Image from 'next/image';

Expand Down
2 changes: 1 addition & 1 deletion src/components/SignupAnonUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { RefObject, useRef, useState } from 'react';
import { AxiosError } from 'axios';

import { api } from '@/lib/axios';
import statusCodes from '@/httpStatusCodes';
import statusCodes from '@/shared/constants/httpStatusCodes';
import { useAuth } from '@/context/AuthContext';

const SignupAnonUser = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/chatSocket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @typedef {import('socket.io-client').Socket} Socket
*/
import events from '@/constants';
import events from '@/shared/constants/constants';
import { MessageType } from '@/types/types';
import { Socket } from 'socket.io-client';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/anonymous.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'react';
import { useRouter } from 'next/navigation';

import events from '@/constants';
import events from '@/shared/constants/constants';

import { Dropdown, IconButton, Tooltip, Whisper } from 'rsuite';
import { Icon } from '@iconify/react';
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Server, Socket } from 'socket.io';
import type { Server as HTTPServer } from 'http';
import type { Socket as NetSocket } from 'net';

import * as handlers from '@/handlers';
import executeHandlers from '@/handlerDecorator';
import * as handlers from '@/server/handlers';
import executeHandlers from '@/server/handlerDecorator';

import connectMongo from '@/service/mongo';
import connectMongo from '@/server/service/mongo';

interface SocketServer extends HTTPServer {
io?: Server | undefined;
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NextApiRequest, NextApiResponse } from 'next';
import axios from 'axios';

import statusCodes from '@/httpStatusCodes';
import { UserModel } from '@/models/UserModel';
import { emailValidator } from '@/lib/userAPI';
import statusCodes from '@/shared/constants/httpStatusCodes';
import { UserModel } from '@/server/models/UserModel';
import { emailValidator } from '@/server/lib/userAPI';

let accessToken = process.env.ACCESS_TOKEN;
const domain = process.env.DOMAIN;
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/user/login.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { UserModel } from '@/models/UserModel';
import { createUserWithAutoId, emailValidator } from '@/lib/userAPI';
import statusCodes from '@/httpStatusCodes';
import { UserModel } from '@/server/models/UserModel';
import { createUserWithAutoId, emailValidator } from '@/server/lib/userAPI';
import statusCodes from '@/shared/constants/httpStatusCodes';

export default async (req: NextApiRequest, res: NextApiResponse) => {
emailValidator(req, res, async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/user/profile/[email].ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { UserModel } from '@/models/UserModel';
import { emailValidator } from '@/lib/userAPI';
import statusCodes from '@/httpStatusCodes';
import { UserModel } from '@/server/models/UserModel';
import { emailValidator } from '@/server/lib/userAPI';
import statusCodes from '@/shared/constants/httpStatusCodes';

export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'GET') {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/user/profile/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next';

import { UserModel } from '@/models/UserModel';
import { emailValidator } from '@/lib/userAPI';
import statusCodes from '@/httpStatusCodes';
import { UserModel } from '@/server/models/UserModel';
import { emailValidator } from '@/server/lib/userAPI';
import statusCodes from '@/shared/constants/httpStatusCodes';

export default async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'POST') {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/verification/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { ApiError } from 'next/dist/server/api-utils';

import httpStatusCodes from '@/httpStatusCodes';
import httpStatusCodes from '@/shared/constants/httpStatusCodes';
import sendMail from '@/service/mailService';

export default async (req: NextApiRequest, res: NextApiResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/searching.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useAuth } from '@/context/AuthContext';
import { useApp } from '@/context/AppContext';
import { useChat } from '@/context/ChatContext';

import events from '@/constants';
import events from '@/shared/constants/constants';

import { useNotification } from '@/lib/notification';
import { createBrowserNotification } from '@/lib/browserNotification';
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/handlers.ts β†’ src/server/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Server, Socket } from 'socket.io';

import constants from '@/constants';
import constants from '@/shared/constants/constants';
import { ChatIdType, OnlineStatus } from '@/types/types';
import {
chatExists,
Expand All @@ -17,7 +17,7 @@ import {
delWaitingUser,
seenMessage,
addMessage,
} from '@/lib/lib';
} from '@/server/lib/lib';

export const CloseChatHandler = (socket: Socket) => {
socket.on(
Expand Down
6 changes: 3 additions & 3 deletions src/lib/lib.ts β†’ src/server/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Socket } from 'socket.io';
import mongoose from 'mongoose';
import CryptoJS from 'crypto-js';

import ActiveUser from '../models/ActiveUserModel';
import Chat from '../models/ChatModel';
import Message from '../models/MessageModel';
import ActiveUser from '@/server/models/ActiveUserModel';
import Chat from '@/server/models/ChatModel';
import Message from '@/server/models/MessageModel';
import {
ChatIdType,
activeUserIdType,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/userAPI.ts β†’ src/server/lib/userAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { NextApiRequest, NextApiResponse } from 'next';
import validator from 'validator';
import { v4 as uuidv4 } from 'uuid';

import { UserModel } from '@/models/UserModel';
import statusCodes from '@/httpStatusCodes';
import connectMongo from '@/service/mongo';
import { UserModel } from '@/server/models/UserModel';
import statusCodes from '@/shared/constants/httpStatusCodes';
import connectMongo from '@/server/service/mongo';

export const createUserWithAutoId = async (email: string) => {
// Logic to create a new user with an autogenerated ID
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/shared/lib/.gitkeep
Dun-sin marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
File renamed without changes.
Loading