diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index cfd046b1..a3877a42 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -1,6 +1,6 @@ // src/controllers/UserController.ts import { Request, Response } from "express"; -import { UserService } from "../services/UserServivce"; +import { UserService } from "../services/user.services"; class UserController { private userService: UserService; diff --git a/src/models/article.ts b/src/models/helpcentertopic.ts similarity index 70% rename from src/models/article.ts rename to src/models/helpcentertopic.ts index 8bce4e45..6f62e0cc 100644 --- a/src/models/article.ts +++ b/src/models/helpcentertopic.ts @@ -4,13 +4,11 @@ import { Column, CreateDateColumn, UpdateDateColumn, - ManyToOne, } from "typeorm"; import ExtendedBaseEntity from "./extended-base-entity"; -import { User } from "."; @Entity() -export class Article extends ExtendedBaseEntity { +export class HelpCenterTopic extends ExtendedBaseEntity { @PrimaryGeneratedColumn("uuid") id: string; @@ -20,8 +18,8 @@ export class Article extends ExtendedBaseEntity { @Column() content: string; - @ManyToOne(() => User, (user) => user.articles) - author: User; + @Column() + author: string; @CreateDateColumn() createdAt: Date; diff --git a/src/models/index.ts b/src/models/index.ts index bffdf60d..bbe502d2 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,5 +1,6 @@ -export * from "./User"; -export * from "./Organization"; -export * from "./Profile"; -export * from "./Product"; -export * from "./article"; +export * from "./user"; +export * from "./organization"; +export * from "./profile"; +export * from "./product"; +export * from "./helpcentertopic"; +export * from "./notification"; diff --git a/src/models/notification.ts b/src/models/notification.ts new file mode 100644 index 00000000..170121a1 --- /dev/null +++ b/src/models/notification.ts @@ -0,0 +1,21 @@ +import { Entity, PrimaryGeneratedColumn, Column, Unique } from "typeorm"; +import ExtendedBaseEntity from "./extended-base-entity"; + +@Entity() +@Unique(["user_id"]) +export class NotificationSetting extends ExtendedBaseEntity { + @PrimaryGeneratedColumn() + id: number; + + @Column() + user_id: string; + + @Column() + email_notifications: boolean; + + @Column() + push_notifications: boolean; + + @Column() + sms_notifications: boolean; +} diff --git a/src/models/Organization.ts b/src/models/organization.ts similarity index 92% rename from src/models/Organization.ts rename to src/models/organization.ts index e4c69a89..c0360084 100644 --- a/src/models/Organization.ts +++ b/src/models/organization.ts @@ -1,5 +1,5 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToMany } from "typeorm"; -import { User } from "./User"; +import { User } from "./user"; import ExtendedBaseEntity from "./extended-base-entity"; @Entity() diff --git a/src/models/Product.ts b/src/models/product.ts similarity index 92% rename from src/models/Product.ts rename to src/models/product.ts index b944e150..0f1986cd 100644 --- a/src/models/Product.ts +++ b/src/models/product.ts @@ -1,5 +1,5 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; -import { User } from "./User"; +import { User } from "./user"; import ExtendedBaseEntity from "./extended-base-entity"; @Entity() diff --git a/src/models/Profile.ts b/src/models/profile.ts similarity index 93% rename from src/models/Profile.ts rename to src/models/profile.ts index 0b1bbf0e..8c80f773 100644 --- a/src/models/Profile.ts +++ b/src/models/profile.ts @@ -1,5 +1,5 @@ import { Entity, PrimaryGeneratedColumn, Column, OneToOne } from "typeorm"; -import { User } from "./User"; +import { User } from "./user"; import ExtendedBaseEntity from "./extended-base-entity"; @Entity() diff --git a/src/models/sms.ts b/src/models/sms.ts new file mode 100644 index 00000000..5461139f --- /dev/null +++ b/src/models/sms.ts @@ -0,0 +1,28 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + CreateDateColumn, + ManyToOne, +} from "typeorm"; +import ExtendedBaseEntity from "./extended-base-entity"; +import { User } from "."; + +@Entity() +export class Sms extends ExtendedBaseEntity { + @PrimaryGeneratedColumn("uuid") + id: string; + + @Column() + phone_number: string; + + @Column() + message: string; + + @Column() + @ManyToOne(() => User, (user) => user.id) + sender_id: User; + + @CreateDateColumn() + createdAt: Date; +} diff --git a/src/models/User.ts b/src/models/user.ts similarity index 89% rename from src/models/User.ts rename to src/models/user.ts index 466e5108..3deba662 100644 --- a/src/models/User.ts +++ b/src/models/user.ts @@ -11,7 +11,7 @@ import { CreateDateColumn, UpdateDateColumn, } from "typeorm"; -import { Profile, Product, Organization, Article } from "."; +import { Profile, Product, Organization } from "."; import { IsEmail } from "class-validator"; import ExtendedBaseEntity from "./extended-base-entity"; import { getIsInvalidMessage } from "../utils"; @@ -59,9 +59,6 @@ export class User extends ExtendedBaseEntity { @JoinTable() products: Product[]; - @OneToMany(() => Article, (article) => article.author, { cascade: true }) - articles: Article[]; - @ManyToMany(() => Organization, (organization) => organization.users, { cascade: true, }) diff --git a/src/services/auth.services.ts b/src/services/auth.services.ts index 3b3a96ed..741f3ea6 100644 --- a/src/services/auth.services.ts +++ b/src/services/auth.services.ts @@ -1,5 +1,5 @@ import { AppDataSource } from "../data-source"; -import { User } from "../models"; +import { Profile, User } from "../models"; import { IAuthService, IUserSignUp, IUserLogin } from "../types"; import { Conflict, HttpError } from "../middleware"; import { hashPassword, generateNumericOTP, comparePassword } from "../utils"; @@ -92,7 +92,9 @@ export class AuthService implements IAuthService { } } - public async login(payload: IUserLogin): Promise<{ access_token: string; user: Partial }> { + public async login( + payload: IUserLogin + ): Promise<{ access_token: string; user: Partial }> { const { email, password } = payload; try { @@ -107,7 +109,13 @@ export class AuthService implements IAuthService { throw new HttpError(401, "Invalid credentials"); } - const access_token = jwt.sign({ userId: user.id }, config.TOKEN_SECRET, { expiresIn: "1d" }); + if (!user.isverified) { + throw new HttpError(403, "Email not verified"); + } + + const access_token = jwt.sign({ userId: user.id }, config.TOKEN_SECRET, { + expiresIn: "1d", + }); const { password: _, ...userWithoutPassword } = user; diff --git a/src/services/index.ts b/src/services/index.ts index 18c05b36..1578dc12 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,2 +1,2 @@ export * from "./auth.services"; -export * from "./UserServivce"; +export * from "./user.services"; diff --git a/src/services/UserServivce.ts b/src/services/user.services.ts similarity index 92% rename from src/services/UserServivce.ts rename to src/services/user.services.ts index 9e19e61a..f002409c 100644 --- a/src/services/UserServivce.ts +++ b/src/services/user.services.ts @@ -1,5 +1,5 @@ // src/services/UserService.ts -import { User } from "../models/User"; +import { User } from "../models/user"; import { IUserService } from "../types"; export class UserService implements IUserService { diff --git a/src/types/index.d.ts b/src/types/index.d.ts index d0d925ad..e93462c8 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -9,7 +9,7 @@ export interface IRole { role: "super_admin" | "admin" | "user"; } -interface IUserSignUp { +export interface IUserSignUp { firstName: string; lastName: string; email: string; @@ -17,8 +17,13 @@ interface IUserSignUp { phone: string; } +export interface IUserLogin { + email: string; + password: string; +} + export interface IAuthService { - // login(email: string, password: string): Promise; + login(payload: IUserLogin): Promise; signUp(payload: IUserSignUp, res: unknown): Promise; verifyEmail(token: string, otp: number): Promise<{ message: string }>; }