.
This commit is contained in:
1 parent
3607e3a99c
commit
905e72fbed
13 files changed
+389
-40
No files matched your search
@@ -55,6 +55,9 @@ export class AuctionController {
|
||||
initialPoints: body.initialPoints ?? 1000,
|
||||
maxTimerSeconds: body.maxTimerSeconds ?? 30,
|
||||
topTierThreshold: body.topTierThreshold ?? 'NONE',
|
||||
manualTopTierUserIds: (body.manualTopTierUserIds ?? []).map(
|
||||
(userId) => new mongoose.Types.ObjectId(userId),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ interface StartAuctionParams {
|
||||
initialPoints: number;
|
||||
maxTimerSeconds: number;
|
||||
topTierThreshold: AuctionTopTierThreshold;
|
||||
manualTopTierUserIds: mongoose.Types.ObjectId[];
|
||||
}
|
||||
|
||||
interface PlaceBidParams {
|
||||
@@ -168,6 +169,7 @@ export class AuctionService {
|
||||
const prioritizedOrder = this.applyTopTierPriority(
|
||||
order,
|
||||
params.topTierThreshold,
|
||||
params.manualTopTierUserIds,
|
||||
);
|
||||
|
||||
const auction = await AuctionModel.create({
|
||||
@@ -188,6 +190,8 @@ export class AuctionService {
|
||||
maxTimerSeconds: params.maxTimerSeconds,
|
||||
initialPoints: params.initialPoints,
|
||||
topTierThreshold: params.topTierThreshold,
|
||||
manualTopTierUserIds:
|
||||
params.topTierThreshold === 'MANUAL' ? params.manualTopTierUserIds : [],
|
||||
startedAt: new Date(),
|
||||
});
|
||||
await this.recordSnapshot(auction, 'start');
|
||||
@@ -532,8 +536,22 @@ export class AuctionService {
|
||||
private applyTopTierPriority(
|
||||
order: AuctionPlayerSnapshot[],
|
||||
threshold: AuctionTopTierThreshold,
|
||||
manualTopTierUserIds: mongoose.Types.ObjectId[],
|
||||
): AuctionPlayerSnapshot[] {
|
||||
if (threshold === 'NONE') return order;
|
||||
if (threshold === 'MANUAL') {
|
||||
const manualIds = new Set(
|
||||
manualTopTierUserIds.map((userId) => userId.toString()),
|
||||
);
|
||||
if (manualIds.size === 0) return order;
|
||||
const selected = order.filter((snap) =>
|
||||
manualIds.has(snap.userId.toString()),
|
||||
);
|
||||
const rest = order.filter(
|
||||
(snap) => !manualIds.has(snap.userId.toString()),
|
||||
);
|
||||
return [...selected, ...rest];
|
||||
}
|
||||
|
||||
const ranks = [
|
||||
'IRON',
|
||||
|
||||
@@ -49,6 +49,12 @@ export class StartAuctionDto {
|
||||
@IsEnum(AUCTION_TOP_TIER_THRESHOLDS)
|
||||
topTierThreshold?: AuctionTopTierThreshold;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(100)
|
||||
@IsMongoId({ each: true })
|
||||
manualTopTierUserIds?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(5)
|
||||
|
||||
@@ -62,6 +62,10 @@ export async function migrateAuctionPassHistory(
|
||||
set.topTierThreshold = 'NONE';
|
||||
changed = true;
|
||||
}
|
||||
if (!Array.isArray(doc.manualTopTierUserIds)) {
|
||||
set.manualTopTierUserIds = [];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
const order = Array.isArray(doc.order)
|
||||
? doc.order.map((player) => {
|
||||
|
||||
@@ -112,6 +112,7 @@ export const AUCTION_TOP_TIER_THRESHOLDS = [
|
||||
'EMERALD',
|
||||
'DIAMOND',
|
||||
'MASTER',
|
||||
'MANUAL',
|
||||
] as const;
|
||||
export type AuctionTopTierThreshold =
|
||||
(typeof AUCTION_TOP_TIER_THRESHOLDS)[number];
|
||||
@@ -535,6 +536,7 @@ export interface Auction extends MongooseTimestamps {
|
||||
currentDeadline?: Date;
|
||||
initialPoints: number;
|
||||
topTierThreshold: AuctionTopTierThreshold;
|
||||
manualTopTierUserIds: mongoose.Types.ObjectId[];
|
||||
startedAt?: Date;
|
||||
completedAt?: Date;
|
||||
}
|
||||
@@ -1306,6 +1308,12 @@ export const AuctionSchema = new Schema<Auction>(
|
||||
required: true,
|
||||
default: 'NONE',
|
||||
},
|
||||
manualTopTierUserIds: {
|
||||
type: [Schema.Types.ObjectId],
|
||||
ref: 'user',
|
||||
required: true,
|
||||
default: [],
|
||||
},
|
||||
startedAt: { type: Date, required: false },
|
||||
completedAt: { type: Date, required: false },
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user