Skip to content

Commit

Permalink
change merchant module to singlecleint (#461)
Browse files Browse the repository at this point in the history
Co-authored-by: Olasunkanmi Oyinlola <olasunkanmioyinlola@Olasunkanmis-Mac-mini.local>
  • Loading branch information
olasunkanmi-SE and Olasunkanmi Oyinlola committed Dec 11, 2023
1 parent 7521439 commit de0166a
Show file tree
Hide file tree
Showing 88 changed files with 968 additions and 946 deletions.
19 changes: 8 additions & 11 deletions backend/src/addon/addon.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SingleClientMapper } from '../singleclient/singleclient.mapper';
import { SingleClientRepository } from './../infrastructure/data_access/repositories/singleclient.repository';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { MongooseModule } from '@nestjs/mongoose';
Expand All @@ -8,43 +10,38 @@ import { AuthService } from './../infrastructure/auth/auth.service';
import { ContextService } from './../infrastructure/context/context.service';
import { AddonRepository } from './../infrastructure/data_access/repositories/addon.repository';
import { CategoryRepository } from './../infrastructure/data_access/repositories/category.repository';
import { MerchantRepository } from './../infrastructure/data_access/repositories/merchant.repository';
import {
CategoryDataModel,
CategorySchema,
} from './../infrastructure/data_access/repositories/schemas/category.schema';
import {
MerchantDataModel,
MerchantSchema,
} from './../infrastructure/data_access/repositories/schemas/merchant.schema';
import { ContextMiddleWare } from './../infrastructure/middlewares/context.middleware';
import { MerchantMapper } from './../merchant/merchant.mapper';
import { MerchantService } from './../merchant/merchant.service';
import { ValidateUser } from './../utils/context-validation';
import { AddonController } from './addon.controller';
import { AddonMapper } from './addon.mapper';
import { AddonDataModel, AddonSchema } from './addon.schema';
import { AddonService } from './addon.service';
import { SingleClientDataModel, SingleClientSchema } from '../infrastructure';
import { SingleClientService } from 'src/singleclient/singleclient.service';

@Module({
imports: [
MongooseModule.forFeature([
{ name: AddonDataModel.name, schema: AddonSchema },
{ name: MerchantDataModel.name, schema: MerchantSchema },
{ name: SingleClientDataModel.name, schema: SingleClientSchema },
{ name: CategoryDataModel.name, schema: CategorySchema },
]),
],
controllers: [AddonController],
providers: [
{ provide: TYPES.IContextService, useClass: ContextService },
{ provide: TYPES.IMerchantService, useClass: MerchantService },
{ provide: TYPES.ISingleClientService, useClass: SingleClientService },
{ provide: TYPES.IAuthService, useClass: AuthService },
{ provide: TYPES.IValidateUser, useClass: ValidateUser },
{ provide: TYPES.IAddonService, useClass: AddonService },
AddonRepository,
AddonMapper,
MerchantRepository,
MerchantMapper,
SingleClientRepository,
SingleClientMapper,
JwtService,
AuditMapper,
CategoryRepository,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/addon/addon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { Context } from './../infrastructure/context/context';
import { IContextService } from './../infrastructure/context/context-service.interface';
import { AddonRepository } from './../infrastructure/data_access/repositories/addon.repository';
import { throwApplicationError } from './../infrastructure/utilities/exception-instance';
import { IMerchantService } from './../merchant/interface/merchant-service.interface';
import { Addon } from './addon';
import { IAddonService } from './addon-service.interface';
import { AddonMapper } from './addon.mapper';
import { AddonDataModel } from './addon.schema';
import { CreateAddonDTO } from './create-addon.dto';
import { ISingleClientService } from '../singleclient/interface/singleclient-service.interface';

@Injectable()
export class AddonService implements IAddonService {
private context: Context;
constructor(
@Inject(TYPES.IContextService)
private readonly contextService: IContextService,
@Inject(TYPES.IMerchantService) private readonly merchantService: IMerchantService,
@Inject(TYPES.ISingleClientService) private readonly singleclientService: ISingleClientService,
private readonly categoryRepository: CategoryRepository,
private readonly addonRepository: AddonRepository,
private readonly addonMapper: AddonMapper,
Expand All @@ -33,7 +33,7 @@ export class AddonService implements IAddonService {

async createAddon(props: CreateAddonDTO): Promise<Result<IAddonResponseDTO>> {
const { name } = props;
await this.merchantService.validateContext();
await this.singleclientService.validateContext();
const existingItem = await this.addonRepository.findOne({ name });
if (existingItem.isSuccess) {
throwApplicationError(HttpStatus.BAD_REQUEST, `Item ${name} already exists`);
Expand All @@ -57,7 +57,7 @@ export class AddonService implements IAddonService {
}

async getAddons(): Promise<Result<IAddonResponseDTO[]>> {
await this.merchantService.validateContext();
await this.singleclientService.validateContext();
const addonsDoc = await this.addonRepository.getAddons();
const addons: Addon[] = addonsDoc.map((addon) => this.addonMapper.toDomain(addon));
const response: IAddonResponseDTO[] = AddonParser.createAddonsResponse(addons);
Expand Down
4 changes: 2 additions & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AuthModule } from './infrastructure/auth';
import { ContextService } from './infrastructure/context';
import { ContextMiddleWare } from './infrastructure/middlewares';
import { ItemModule } from './item/item.module';
import { MerchantModule } from './merchant/merchant.module';
import { SingleClientModule } from './singleclient/singleclient.module';
import { ApplicationExceptionsFilter, ApplicationLogger } from './infrastructure';
import { LocationModule } from './location';
import { OrderModule } from './order/order.module';
Expand Down Expand Up @@ -44,7 +44,7 @@ import { OrderProcessingQueuesModule } from './order_processing_queue/order_proc
ConfigModule.forRoot(),
LocationModule,
RestaurantModule,
MerchantModule,
SingleClientModule,
AuthModule,
ItemModule,
MenuModule,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/application/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const APIResponseMessage = {

export const saltRounds = 10;

export enum MerchantStatus {
export enum SingleClientStatus {
onBoarding = 'onBoarding',
boarded = 'boarded',
banned = 'banned',
Expand Down
4 changes: 2 additions & 2 deletions backend/src/application/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const TYPES = {
IApplicationLogger: Symbol('IApplicationLogger'),
ILocationService: Symbol('ILocationService'),
IRestaurantService: Symbol('IRestaurantService'),
IMerchantService: Symbol('IMerchantService'),
ISingleClientService: Symbol('ISingleClientService'),
IRestaurantRepository: Symbol('IRestaurantRepository'),
IItemService: Symbol('IItemService'),
IMenuService: Symbol('IMenuService'),
Expand All @@ -29,7 +29,7 @@ export const TYPES = {
IOrderNoteService: Symbol('IOrderNoteService'),
IOrderProcessingQueueRepository: Symbol('IOrderProcessingQueueRepository'),
IOrderProcessingQueueService: Symbol('IOrderProcessingQueueService'),
IMerchantRepository: Symbol('IMerchantRepository'),
ISingleClientRepository: Symbol('ISingleClientRepository'),
IRoleService: Symbol('IRoleService'),
IAccessControlService: Symbol('IAccessControlService'),
};
20 changes: 10 additions & 10 deletions backend/src/category/category.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { AuditMapper } from './../audit/audit.mapper';
import { AuthService } from './../infrastructure/auth/auth.service';
import { ContextService } from './../infrastructure/context/context.service';
import { CategoryRepository } from './../infrastructure/data_access/repositories/category.repository';
import { MerchantRepository } from './../infrastructure/data_access/repositories/merchant.repository';
import { SingleClientRepository } from './../infrastructure/data_access/repositories/singleclient.repository';
import {
CategoryDataModel,
CategorySchema,
} from './../infrastructure/data_access/repositories/schemas/category.schema';
import {
MerchantDataModel,
MerchantSchema,
} from './../infrastructure/data_access/repositories/schemas/merchant.schema';
SingleClientDataModel,
SingleClientSchema,
} from './../infrastructure/data_access/repositories/schemas/singleclient.schema';
import { ContextMiddleWare } from './../infrastructure/middlewares/context.middleware';
import { MerchantMapper } from './../merchant/merchant.mapper';
import { MerchantService } from './../merchant/merchant.service';
import { SingleClientMapper } from './../singleclient/singleclient.mapper';
import { SingleClientService } from './../singleclient/singleclient.service';
import { ValidateUser } from './../utils/context-validation';
import { CategoryController } from './category.controller';
import { CategoryMapper } from './category.mapper';
Expand All @@ -26,21 +26,21 @@ import { CategoryService } from './category.service';
imports: [
MongooseModule.forFeature([
{ name: CategoryDataModel.name, schema: CategorySchema },
{ name: MerchantDataModel.name, schema: MerchantSchema },
{ name: SingleClientDataModel.name, schema: SingleClientSchema },
]),
],
controllers: [CategoryController],
providers: [
{ provide: TYPES.IContextService, useClass: ContextService },
{ provide: TYPES.IMerchantService, useClass: MerchantService },
{ provide: TYPES.ISingleClientService, useClass: SingleClientService },
{ provide: TYPES.IAuthService, useClass: AuthService },
{ provide: TYPES.IValidateUser, useClass: ValidateUser },
{ provide: TYPES.ICategoryService, useClass: CategoryService },
CategoryRepository,
JwtService,
AuditMapper,
MerchantRepository,
MerchantMapper,
SingleClientRepository,
SingleClientMapper,
CategoryMapper,
],
})
Expand Down
10 changes: 5 additions & 5 deletions backend/src/category/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Result } from './../domain/result/result';
import { IContextService } from './../infrastructure/context/context-service.interface';
import { CategoryRepository } from './../infrastructure/data_access/repositories/category.repository';
import { throwApplicationError } from './../infrastructure/utilities/exception-instance';
import { IMerchantService } from './../merchant/interface/merchant-service.interface';
import { ISingleClientService } from './../singleclient/interface/singleclient-service.interface';
import { Category } from './category';
import { ICategoryService } from './category-service.interface';
import { CategoryMapper } from './category.mapper';
Expand All @@ -21,7 +21,7 @@ export class CategoryService implements ICategoryService {
private context: Context;
constructor(
@Inject(TYPES.IContextService) private readonly contextService: IContextService,
@Inject(TYPES.IMerchantService) private readonly merchantService: IMerchantService,
@Inject(TYPES.ISingleClientService) private readonly singleclientService: ISingleClientService,
private readonly categoryRepository: CategoryRepository,
private readonly categoryMapper: CategoryMapper,
) {
Expand All @@ -30,7 +30,7 @@ export class CategoryService implements ICategoryService {
async createCategory(props: CreateCategoryDTO): Promise<Result<ICategoryResponseDTO>> {
const { name } = props;
const code = name.toUpperCase();
await this.merchantService.validateContext();
await this.singleclientService.validateContext();
const existingItem = await this.categoryRepository.findOne({ name });
if (existingItem.isSuccess) {
throwApplicationError(HttpStatus.BAD_REQUEST, `Item ${name} already exists`);
Expand All @@ -47,14 +47,14 @@ export class CategoryService implements ICategoryService {
}

async getCategories(): Promise<Result<ICategoryResponseDTO[]>> {
await this.merchantService.validateContext();
await this.singleclientService.validateContext();
const result: Result<Category[]> = await this.categoryRepository.find({});
const response: ICategoryResponseDTO[] = CategoryParser.createCategoriesResponse(result.getValue());
return Result.ok(response);
}

async getCategoryById(id: Types.ObjectId): Promise<Result<ICategoryResponseDTO>> {
await this.merchantService.validateContext();
await this.singleclientService.validateContext();
const result: Result<Category> = await this.categoryRepository.findById(id);
const response: ICategoryResponseDTO = CategoryParser.createCategoryResponse(result.getValue());
return Result.ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './interfaces/addon-repository.interface';
export * from './addon.repository';
export * from './item.repository';
export * from './menu.repopsitory';
export * from './merchant.repository';
export * from './singleclient.repository';
export * from './interfaces/addon-repository.interface';
export * from './addon.repository';
export * from './order-manager.repository';
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface IMenuRepository {
getMenuById(id: Types.ObjectId): Promise<any>;
createMenu(menuModel: MenuDataModel): Promise<Result<any>>;
deleteMenu(id: Types.ObjectId);
getMenuByRestaurantId(restaurantId: string, merchantId: string): Promise<Result<Menu[]>>;
getMenuByRestaurantId(restaurantId: string, singleclientId: string): Promise<Result<Menu[]>>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IGenericDocument } from 'src/infrastructure/database';
import { Merchant } from 'src/merchant';
import { MerchantDocument } from '../schemas';
import { SingleClient } from 'src/singleclient';
import { SingleClientDocument } from '../schemas';

export interface IMerchantRepository extends IGenericDocument<Merchant, MerchantDocument> {}
export interface ISingleClientRepository extends IGenericDocument<SingleClient, SingleClientDocument> {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { CreateCartItemsDTO } from 'src/order/dto/create-order.dto';

export interface IOrderRepository extends IGenericDocument<Order, OrderDocument> {
createOrder(order: OrderDataModel): Promise<Result<Order>>;
getDuplicateOrder(type: string, merchantId: string, cartItems: CreateCartItemsDTO[]): Promise<boolean>;
getDuplicateOrder(type: string, singleclientId: string, cartItems: CreateCartItemsDTO[]): Promise<boolean>;
getOrders(): Promise<Result<Order[]>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Restaurant } from '../../../../restaurant/restaurant';
import { IGenericDocument } from '../../../database/mongoDB/generic-document.interface';
import { RestaurantDocument } from '../schemas';
export interface IRestaurantRepository extends IGenericDocument<Restaurant, RestaurantDocument> {
getRestaurantWithMerchantDetails(restaurant: Restaurant, merchantId: Types.ObjectId): Promise<Restaurant>;
getRestaurantWithSingleClientDetails(restaurant: Restaurant, singleclientId: Types.ObjectId): Promise<Restaurant>;
getRestaurant(restaurantId: Types.ObjectId): Promise<Restaurant>;
getRestaurants(): Promise<Restaurant[]>;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './location-model.interface';
export * from './merchant-model.interface';
export * from './singleclient-model.interface';
export * from './restaurant-model.interface';
export * from './item-model.interface';
export * from './menu-model.interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MerchantDataModel } from '../schemas';
import { SingleClientDataModel } from '../schemas';

export interface IOrderManagerDataModel {
readonly firstName: string;
readonly lastName: string;
readonly email: string;
readonly phoneNumber?: string;
readonly merchant: MerchantDataModel;
readonly singleclient: SingleClientDataModel;
readonly role: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OrderStatusModel } from '../schemas/order-status.schema';
export interface IOrderDataModel {
readonly state: OrderStatusModel;
readonly type: dinningType;
readonly merchantId: Types.ObjectId;
readonly singleclientId: Types.ObjectId;
readonly customerId?: Types.ObjectId;
readonly total: number;
readonly discount?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IRestaurantdata {
readonly logoUrl?: string;
readonly timeZone?: string;
readonly phoneNumber: string;
readonly merchantId: Types.ObjectId;
readonly singleclientId: Types.ObjectId;
readonly location: LocationData;
readonly opened: boolean;
readonly imageUrl: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface IMerchantData {
export interface ISingleClientData {
readonly firstName: string;
readonly lastName: string;
readonly email: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class OrderRepository extends GenericDocumentRepository<Order, OrderDocum
return response ? Result.ok(response) : Result.fail('Could not create order', HttpStatus.INTERNAL_SERVER_ERROR);
}

async getDuplicateOrder(type: string, merchantId: string, cartItems: CreateCartItemsDTO[]): Promise<boolean> {
async getDuplicateOrder(type: string, singleclientId: string, cartItems: CreateCartItemsDTO[]): Promise<boolean> {
const currentTime: Date = new Date();
const initDuplicateTimeFrameInMinutes = 60 * 1000;
const finalDuplicateTimeFrameInMinutes = initDuplicateTimeFrameInMinutes * 4;
Expand All @@ -35,7 +35,7 @@ export class OrderRepository extends GenericDocumentRepository<Order, OrderDocum
const selectedItemIds = selectedItems.map((item) => item.itemId);
const result: Result<Order[]> = await this.find({
type,
merchantId,
singleclientId,
cartItems: { $elemMatch: { $in: selectedItemIds } },
auditCreatedDateTime: {
$gte: initDuplicateTimeInMilliSeconds,
Expand Down
Loading

0 comments on commit de0166a

Please sign in to comment.