Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/clan/clan.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, forwardRef } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ClanSchema } from './clan.schema';
import { ClanController } from './clan.controller';
Expand Down Expand Up @@ -27,11 +27,11 @@ import { EventEmitterCommonModule } from '../common/service/EventEmitterService/
{ name: ModelName.CLAN, schema: ClanSchema },
{ name: ModelName.PLAYER, schema: PlayerSchema },
]),
ClanInventoryModule,
forwardRef(() => ClanInventoryModule),
RequestHelperModule,
PlayerModule,
GameEventsEmitterModule,
VotingModule,
forwardRef(() => VotingModule),
ChatModule,
EventEmitterCommonModule,
],
Expand All @@ -53,4 +53,4 @@ import { EventEmitterCommonModule } from '../common/service/EventEmitterService/
PasswordGenerator,
],
})
export class ClanModule {}
export class ClanModule {}
5 changes: 4 additions & 1 deletion src/clan/clan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export class ClanService {
@InjectConnection() private readonly connection: Connection,
@Inject(PasswordGenerator)
private readonly passwordGenerator: PasswordGenerator,

@Inject(forwardRef(() => StockService)) // <-- MAOC FIX APPLIED HERE
private readonly stockService: StockService,

private readonly soulhomeService: SoulHomeService,
private readonly clanHelperService: ClanHelperService,
private readonly emitter: GameEventEmitter,
Expand Down Expand Up @@ -364,4 +367,4 @@ export class ClanService {

return await endTransaction<true>(session, true);
}
}
}
3 changes: 2 additions & 1 deletion src/clan/utils/clanHelper.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Inject, forwardRef } from '@nestjs/common';
import {
getStockDefaultItems,
getRoomDefaultItems,
Expand All @@ -19,6 +19,7 @@ import { ClientSession } from 'mongoose';
@Injectable()
export default class ClanHelperService {
constructor(
@Inject(forwardRef(() => StockService))
private readonly stockService: StockService,
private readonly soulHomeService: SoulHomeService,
private readonly roomService: RoomService,
Expand Down
9 changes: 6 additions & 3 deletions src/clanInventory/clanInventory.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, forwardRef } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ModelName } from '../common/enum/modelName.enum';
import { PlayerSchema } from '../player/schemas/player.schema';
Expand All @@ -23,7 +23,8 @@ import { StockSchema } from './stock/stock.schema';
import { StockService } from './stock/stock.service';
import { ClanSchema } from '../clan/clan.schema';
import { StealTokenGuard } from './item/guards/StealToken.guard';
import { AuthorizationModule } from '../authorization/authorization.module';
import { AuthorizationModule } from '../authorization/authorization.module'
import { FleaMarketModule } from '../fleaMarket/fleaMarket.module';

@Module({
imports: [
Expand All @@ -39,6 +40,8 @@ import { AuthorizationModule } from '../authorization/authorization.module';
RequestHelperModule,
AuthModule,
AuthorizationModule,

forwardRef(() => FleaMarketModule),
],
controllers: [
StockController,
Expand Down Expand Up @@ -67,4 +70,4 @@ import { AuthorizationModule } from '../authorization/authorization.module';
SoulHomeService,
],
})
export class ClanInventoryModule {}
export class ClanInventoryModule {}
8 changes: 8 additions & 0 deletions src/clanInventory/stock/dto/stock.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ItemDto } from '../../item/dto/item.dto';
import { ClanDto } from '../../../clan/dto/clan.dto';
import AddType from '../../../common/base/decorator/AddType.decorator';
import { ExtractField } from '../../../common/decorator/response/ExtractField';
import { FleaMarketItemDto } from '../../../fleaMarket/dto/fleaMarketItem.dto';

@AddType('StockDto')
export class StockDto {
Expand Down Expand Up @@ -45,4 +46,11 @@ export class StockDto {
@Type(() => ItemDto)
@Expose()
Item: ItemDto[];

/**
* FleaMarketItems associated with this stock's clan
*/
@Type(() => FleaMarketItemDto)
@Expose()
FleaMarketItem: FleaMarketItemDto[];
}
8 changes: 4 additions & 4 deletions src/clanInventory/stock/stock.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export class StockController {

/**
* Get stock by _id
*
* @remarks Read Stock data by its _id field.
*
* Notice that everybody is able to read any Stock data.
* @remarks Returns the Stock document with the given _id. Includes both the
* clan's active stock items (under `Item`) and FleaMarketItems currently in the
* sell lifecycle (under `FleaMarketItem`). Consolidates the complete view of
* clan furniture into a single decoupled request.
*/
@ApiResponseDescription({
success: {
Expand Down
25 changes: 21 additions & 4 deletions src/clanInventory/stock/stock.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, forwardRef, Inject } from '@nestjs/common';
import { Model, ClientSession } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Stock } from './stock.schema';
Expand All @@ -8,6 +8,7 @@ import { StockDto } from './dto/stock.dto';
import { ItemService } from '../item/item.service';
import { ModelName } from '../../common/enum/modelName.enum';
import BasicService from '../../common/service/basicService/BasicService';
import { FleaMarketService } from '../../fleaMarket/fleaMarket.service';
import {
TReadByIdOptions,
TIServiceReadManyOptions,
Expand All @@ -21,6 +22,8 @@ export class StockService {
public constructor(
@InjectModel(Stock.name) public readonly model: Model<Stock>,
private readonly itemService: ItemService,
@Inject(forwardRef(() => FleaMarketService))
private readonly fleaMarketService: FleaMarketService,
) {
this.refsInModel = [ModelName.CLAN, ModelName.ITEM];
this.modelName = ModelName.STOCK;
Expand Down Expand Up @@ -58,7 +61,21 @@ export class StockService {
optionsToApply.includeRefs = options.includeRefs.filter((ref) =>
this.refsInModel.includes(ref),
);
return this.basicService.readOneById<StockDto>(_id, optionsToApply);

const [stock, errors] = await this.basicService.readOneById<StockDto>(
_id,
optionsToApply,
);
if (errors) return [null, errors];

const [fleaMarketItems] = await this.fleaMarketService.basicService.readMany({
filter: { clan_id: stock.clan_id },
});

return [
{ ...stock, FleaMarketItem: fleaMarketItems ?? [] },
null,
];
}

/**
Expand Down Expand Up @@ -90,7 +107,7 @@ export class StockService {
cellCountChange: number,
): Promise<[boolean | null, ServiceError[] | null]> => {
const [stock, errors] = await this.basicService.readOneById<StockDto>(_id);
if (errors || !stock) return [null, errors];
if (errors) return [null, errors];

const { cellCount } = stock;

Expand Down Expand Up @@ -125,4 +142,4 @@ export class StockService {
await this.itemService.deleteAllStockItems(_id, options);
return this.basicService.deleteOneById(_id, options);
}
}
}
2 changes: 1 addition & 1 deletion src/fleaMarket/enum/status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* voting whether to buy it. Lives in the FleaMarketItem collection.
*/
export enum Status {
IN_STOCK = 'in_stock',
AVAILABLE = 'available',
SHIPPING = 'shipping',
BOOKED = 'booked',
IN_STOCK = 'in_stock',
}
8 changes: 4 additions & 4 deletions src/fleaMarket/fleaMarket.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, forwardRef } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ModelName } from '../common/enum/modelName.enum';
import { FleaMarketItemSchema } from './fleaMarketItem.schema';
Expand Down Expand Up @@ -26,10 +26,10 @@ import { EventEmitterCommonModule } from '../common/service/EventEmitterService/
{ name: ModelName.PLAYER, schema: PlayerSchema },
{ name: ModelName.CLAN, schema: ClanSchema },
]),
ClanInventoryModule,
forwardRef(() => ClanInventoryModule),
PlayerModule,
VotingModule,
ClanModule,
forwardRef(() => ClanModule),
RequestHelperModule,
EventEmitterCommonModule,
],
Expand All @@ -40,6 +40,6 @@ import { EventEmitterCommonModule } from '../common/service/EventEmitterService/
FleaMarketVotingProcessor,
StallService,
],
exports: [],
exports: [FleaMarketService],
})
export class FleaMarketModule {}
3 changes: 2 additions & 1 deletion src/fleaMarket/fleaMarket.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Inject, forwardRef } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { InjectConnection, InjectModel } from '@nestjs/mongoose';
import { FleaMarketItem, publicReferences } from './fleaMarketItem.schema';
Expand Down Expand Up @@ -50,6 +50,7 @@ export class FleaMarketService {
private readonly itemService: ItemService,
private readonly votingService: VotingService,
private readonly votingQueue: VotingQueue,
@Inject(forwardRef(() => ClanService))
private readonly clanService: ClanService,
@InjectConnection() private readonly connection: Connection,
) {
Expand Down