Feat : add most token effects

This commit is contained in:
2024-07-14 00:05:47 +02:00
parent 22836f7611
commit af2965edea
7 changed files with 206 additions and 33 deletions
+32 -23
View File
@@ -57,6 +57,11 @@ export function isInTeam(team: Team, player: Player) {
return false;
}
export function getPlayerTeam(game: Game, player: Player) {
return game.teams.find((t) =>
t.players.some((p) => p._id.equals(player._id)),
);
}
export function WithTransaction(
target: any,
propertyKey: string,
@@ -66,30 +71,11 @@ export function WithTransaction(
descriptor.value = function (...args: any[]) {
return new Promise(async (resolve, reject) => {
if (args.at(-1) instanceof mongoose.mongo.ClientSession) {
const data = await originalFunc.apply(this, args).catch((e) => {
if (e instanceof HttpException) {
throw e;
}
reject(
new HttpException(
'Another request is processing',
HttpStatus.TOO_MANY_REQUESTS,
),
);
});
resolve(data);
return data;
} else {
await this.connection
.transaction(async (session) => {
const data = await originalFunc.apply(this, [...args, session]);
resolve(data);
return data;
})
.catch((e) => {
try {
if (args.at(-1) instanceof mongoose.mongo.ClientSession) {
const data = await originalFunc.apply(this, args).catch((e) => {
if (e instanceof HttpException) {
reject(e);
throw e;
}
reject(
new HttpException(
@@ -98,6 +84,29 @@ export function WithTransaction(
),
);
});
resolve(data);
return data;
} else {
await this.connection
.transaction(async (session) => {
const data = await originalFunc.apply(this, [...args, session]);
resolve(data);
return data;
})
.catch((e) => {
if (e instanceof HttpException) {
reject(e);
}
reject(
new HttpException(
'Another request is processing',
HttpStatus.TOO_MANY_REQUESTS,
),
);
});
}
} catch (e) {
reject(e);
}
});
};