Feat : add most token effects
This commit is contained in:
+32
-23
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user