mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
refactor: sepeare user and auth modules
This commit is contained in:
@ -27,6 +27,7 @@ import { JuniorModule } from './junior/junior.module';
|
||||
import { MoneyRequestModule } from './money-request/money-request.module';
|
||||
import { SavingGoalsModule } from './saving-goals/saving-goals.module';
|
||||
import { TaskModule } from './task/task.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
|
||||
@Module({
|
||||
controllers: [],
|
||||
@ -72,6 +73,8 @@ import { TaskModule } from './task/task.module';
|
||||
LookupModule,
|
||||
|
||||
HealthModule,
|
||||
|
||||
UserModule,
|
||||
],
|
||||
providers: [
|
||||
// Global Pipes
|
||||
|
@ -1,24 +1,15 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
import { JuniorModule } from '~/junior/junior.module';
|
||||
import { UserModule } from '~/user/user.module';
|
||||
import { AuthController } from './controllers';
|
||||
import { Device, User } from './entities';
|
||||
import { DeviceRepository, UserRepository } from './repositories';
|
||||
import { AuthService, DeviceService } from './services';
|
||||
import { UserService } from './services/user.service';
|
||||
import { AuthService } from './services';
|
||||
import { AccessTokenStrategy } from './strategies';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User, Device]),
|
||||
JwtModule.register({}),
|
||||
forwardRef(() => CustomerModule),
|
||||
forwardRef(() => JuniorModule),
|
||||
],
|
||||
providers: [AuthService, UserRepository, UserService, DeviceService, DeviceRepository, AccessTokenStrategy],
|
||||
imports: [JwtModule.register({}), JuniorModule, UserModule],
|
||||
providers: [AuthService, AccessTokenStrategy],
|
||||
controllers: [AuthController],
|
||||
exports: [DeviceService, UserService],
|
||||
exports: [],
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { User } from '~/auth/entities';
|
||||
import { ILoginResponse } from '~/auth/interfaces';
|
||||
import { CustomerResponseDto } from '~/customer/dtos/response';
|
||||
import { User } from '~/user/entities';
|
||||
import { UserResponseDto } from './user.response.dto';
|
||||
|
||||
export class LoginResponseDto {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { User } from '~/auth/entities';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { User } from '~/user/entities';
|
||||
|
||||
export class UserResponseDto {
|
||||
@ApiProperty()
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { User } from '~/auth/entities';
|
||||
import { ILoginResponse } from '~/auth/interfaces';
|
||||
import { User } from '~/user/entities';
|
||||
|
||||
export class VerifyUserResponseDto {
|
||||
@ApiProperty()
|
||||
|
@ -7,6 +7,9 @@ import { CacheService } from '~/common/modules/cache/services';
|
||||
import { OtpScope, OtpType } from '~/common/modules/otp/enums';
|
||||
import { OtpService } from '~/common/modules/otp/services';
|
||||
import { JuniorTokenService } from '~/junior/services';
|
||||
import { User } from '../../user/entities';
|
||||
|
||||
import { DeviceService, UserService } from '~/user/services';
|
||||
import { PASSCODE_REGEX, PASSWORD_REGEX } from '../constants';
|
||||
import {
|
||||
CreateUnverifiedUserRequestDto,
|
||||
@ -19,12 +22,9 @@ import {
|
||||
setJuniorPasswordRequestDto,
|
||||
} from '../dtos/request';
|
||||
import { VerifyUserRequestDto } from '../dtos/request/verify-user.request.dto';
|
||||
import { User } from '../entities';
|
||||
import { GrantType, Roles } from '../enums';
|
||||
import { IJwtPayload, ILoginResponse } from '../interfaces';
|
||||
import { removePadding, verifySignature } from '../utils';
|
||||
import { DeviceService } from './device.service';
|
||||
import { UserService } from './user.service';
|
||||
|
||||
const ONE_THOUSAND = 1000;
|
||||
const SALT_ROUNDS = 10;
|
||||
|
@ -1,3 +1 @@
|
||||
export * from './auth.service';
|
||||
export * from './device.service';
|
||||
export * from './user.service';
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '~/auth/entities';
|
||||
import { User } from '~/user/entities';
|
||||
import { NotificationChannel, NotificationScope, NotificationStatus } from '../enums';
|
||||
|
||||
@Entity('notifications')
|
||||
|
@ -2,8 +2,8 @@ import { Module } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { TwilioModule } from 'nestjs-twilio';
|
||||
import { AuthModule } from '~/auth/auth.module';
|
||||
import { buildTwilioOptions } from '~/core/module-options';
|
||||
import { UserModule } from '~/user/user.module';
|
||||
import { NotificationsController } from './controllers';
|
||||
import { Notification } from './entities';
|
||||
import { NotificationsRepository } from './repositories';
|
||||
@ -17,7 +17,7 @@ import { TwilioService } from './services/twilio.service';
|
||||
useFactory: buildTwilioOptions,
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
AuthModule,
|
||||
UserModule,
|
||||
],
|
||||
providers: [NotificationsService, FirebaseService, NotificationsRepository, TwilioService],
|
||||
exports: [NotificationsService],
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
|
||||
import { DeviceService } from '~/auth/services';
|
||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||
import { DeviceService } from '~/user/services';
|
||||
import { OTP_BODY, OTP_TITLE } from '../../otp/constants';
|
||||
import { OtpType } from '../../otp/enums';
|
||||
import { ISendOtp } from '../../otp/interfaces';
|
||||
@ -18,7 +18,7 @@ export class NotificationsService {
|
||||
private readonly notificationRepository: NotificationsRepository,
|
||||
private readonly twilioService: TwilioService,
|
||||
private readonly eventEmitter: EventEmitter2,
|
||||
@Inject(forwardRef(() => DeviceService)) private readonly deviceService: DeviceService,
|
||||
private readonly deviceService: DeviceService,
|
||||
) {}
|
||||
|
||||
async sendPushNotification(userId: string, title: string, body: string) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Column, CreateDateColumn, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { User } from '~/auth/entities';
|
||||
import { User } from '~/user/entities';
|
||||
import { OtpScope, OtpType } from '../enums';
|
||||
|
||||
@Entity('otp')
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuthModule } from '~/auth/auth.module';
|
||||
import { UserModule } from '~/user/user.module';
|
||||
import { CustomerController } from './controllers';
|
||||
import { Customer } from './entities';
|
||||
import { CustomerNotificationSettings } from './entities/customer-notification-settings.entity';
|
||||
@ -8,7 +8,7 @@ import { CustomerRepository } from './repositories/customer.repository';
|
||||
import { CustomerService } from './services';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Customer, CustomerNotificationSettings]), forwardRef(() => AuthModule)],
|
||||
imports: [TypeOrmModule.forFeature([Customer, CustomerNotificationSettings]), forwardRef(() => UserModule)],
|
||||
controllers: [CustomerController],
|
||||
providers: [CustomerService, CustomerRepository],
|
||||
exports: [CustomerService],
|
||||
|
@ -29,5 +29,6 @@ export class UpdateCustomerRequestDto {
|
||||
|
||||
@ApiProperty({ example: '123e4567-e89b-12d3-a456-426614174000' })
|
||||
@IsUUID('4', { message: i18n('validation.IsUUID', { path: 'general', property: 'customer.profilePictureId' }) })
|
||||
@IsOptional()
|
||||
profilePictureId!: string;
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ import {
|
||||
PrimaryColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '~/auth/entities';
|
||||
import { Document } from '~/document/entities';
|
||||
import { Guardian } from '~/guardian/entities/guradian.entity';
|
||||
import { Junior } from '~/junior/entities';
|
||||
import { User } from '~/user/entities';
|
||||
import { CustomerNotificationSettings } from './customer-notification-settings.entity';
|
||||
|
||||
@Entity('customers')
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { FindOptionsWhere, Repository } from 'typeorm';
|
||||
import { User } from '~/auth/entities';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { User } from '~/user/entities';
|
||||
import { UpdateNotificationsSettingsRequestDto } from '../dtos/request';
|
||||
import { Customer } from '../entities';
|
||||
import { CustomerNotificationSettings } from '../entities/customer-notification-settings.entity';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { BadRequestException, forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||
import { User } from '~/auth/entities';
|
||||
import { DeviceService } from '~/auth/services';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { OciService } from '~/document/services';
|
||||
import { User } from '~/user/entities';
|
||||
import { DeviceService } from '~/user/services';
|
||||
import { UpdateCustomerRequestDto, UpdateNotificationsSettingsRequestDto } from '../dtos/request';
|
||||
import { Customer } from '../entities';
|
||||
import { CustomerRepository } from '../repositories/customer.repository';
|
||||
@ -11,7 +11,7 @@ export class CustomerService {
|
||||
constructor(
|
||||
private readonly customerRepository: CustomerRepository,
|
||||
private readonly ociService: OciService,
|
||||
@Inject(forwardRef(() => DeviceService)) private readonly deviceService: DeviceService,
|
||||
private readonly deviceService: DeviceService,
|
||||
) {}
|
||||
async updateNotificationSettings(userId: string, data: UpdateNotificationsSettingsRequestDto, deviceId: string) {
|
||||
const customer = await this.findCustomerById(userId);
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Column, Entity, OneToMany, OneToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||
import { User } from '~/auth/entities';
|
||||
import { Customer } from '~/customer/entities';
|
||||
import { Gift } from '~/gift/entities';
|
||||
import { Junior, Theme } from '~/junior/entities';
|
||||
import { SavingGoal } from '~/saving-goals/entities';
|
||||
import { Task } from '~/task/entities';
|
||||
import { TaskSubmission } from '~/task/entities/task-submissions.entity';
|
||||
import { User } from '~/user/entities';
|
||||
import { DocumentType } from '../enums';
|
||||
|
||||
@Entity('documents')
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuthModule } from '~/auth/auth.module';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
import { UserModule } from '~/user/user.module';
|
||||
import { JuniorController } from './controllers';
|
||||
import { Junior, JuniorRegistrationToken, Theme } from './entities';
|
||||
import { JuniorRepository, JuniorTokenRepository } from './repositories';
|
||||
@ -10,11 +10,7 @@ import { JuniorService, JuniorTokenService, QrcodeService } from './services';
|
||||
@Module({
|
||||
controllers: [JuniorController],
|
||||
providers: [JuniorService, JuniorRepository, JuniorTokenService, JuniorTokenRepository, QrcodeService],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Junior, Theme, JuniorRegistrationToken]),
|
||||
forwardRef(() => AuthModule),
|
||||
CustomerModule,
|
||||
],
|
||||
imports: [TypeOrmModule.forFeature([Junior, Theme, JuniorRegistrationToken]), UserModule, CustomerModule],
|
||||
exports: [JuniorService, JuniorTokenService],
|
||||
})
|
||||
export class JuniorModule {}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { BadRequestException, forwardRef, Inject, Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { UserService } from '~/auth/services';
|
||||
import { PageOptionsRequestDto } from '~/core/dtos';
|
||||
import { CustomerNotificationSettings } from '~/customer/entities/customer-notification-settings.entity';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { UserService } from '~/user/services';
|
||||
import { CreateJuniorRequestDto, SetThemeRequestDto } from '../dtos/request';
|
||||
import { Junior } from '../entities';
|
||||
import { JuniorRepository } from '../repositories';
|
||||
@ -15,8 +15,8 @@ export class JuniorService {
|
||||
constructor(
|
||||
private readonly juniorRepository: JuniorRepository,
|
||||
private readonly juniorTokenService: JuniorTokenService,
|
||||
@Inject(forwardRef(() => UserService)) private readonly userService: UserService,
|
||||
@Inject(forwardRef(() => CustomerService)) private readonly customerService: CustomerService,
|
||||
private readonly userService: UserService,
|
||||
private readonly customerService: CustomerService,
|
||||
) {}
|
||||
|
||||
@Transactional()
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
import { Notification } from '~/common/modules/notification/entities';
|
||||
import { Otp } from '~/common/modules/otp/entities';
|
||||
import { Customer } from '~/customer/entities/customer.entity';
|
||||
import { Roles } from '../enums';
|
||||
import { Roles } from '../../auth/enums';
|
||||
import { Device } from './device.entity';
|
||||
|
||||
@Entity('users')
|
@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { IsNull, Not, Repository } from 'typeorm';
|
||||
import { Device } from '../entities';
|
||||
import { Device } from '../../user/entities';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceRepository {
|
@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { FindOptionsWhere, Repository } from 'typeorm';
|
||||
import { User } from '../entities';
|
||||
import { User } from '../../user/entities';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepository {
|
2
src/user/services/index.ts
Normal file
2
src/user/services/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './device.service';
|
||||
export * from './user.service';
|
@ -3,9 +3,9 @@ import { FindOptionsWhere } from 'typeorm';
|
||||
import { CustomerNotificationSettings } from '~/customer/entities/customer-notification-settings.entity';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { Guardian } from '~/guardian/entities/guradian.entity';
|
||||
import { CreateUnverifiedUserRequestDto } from '../dtos/request';
|
||||
import { CreateUnverifiedUserRequestDto } from '../../auth/dtos/request';
|
||||
import { Roles } from '../../auth/enums';
|
||||
import { User } from '../entities';
|
||||
import { Roles } from '../enums';
|
||||
import { UserRepository } from '../repositories';
|
||||
|
||||
@Injectable()
|
13
src/user/user.module.ts
Normal file
13
src/user/user.module.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
import { Device, User } from './entities';
|
||||
import { DeviceRepository, UserRepository } from './repositories';
|
||||
import { DeviceService, UserService } from './services';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User, Device]), forwardRef(() => CustomerModule)],
|
||||
providers: [UserService, DeviceService, UserRepository, DeviceRepository],
|
||||
exports: [UserService, DeviceService],
|
||||
})
|
||||
export class UserModule {}
|
Reference in New Issue
Block a user