feat(api): refresh Riot ID by PUUID
This commit is contained in:
1 parent
79534cf43c
commit
9cd5850d43
6 files changed
+508
-3
No files matched your search
@@ -59,6 +59,7 @@ export interface EnrichResult {
|
||||
}
|
||||
|
||||
export type RefreshLeagueEntriesResult = 'updated' | 'failed';
|
||||
export type RefreshRiotIdentityResult = 'updated' | 'unchanged' | 'failed';
|
||||
|
||||
@Injectable()
|
||||
export class RiotAccountEnrichmentService {
|
||||
@@ -87,6 +88,56 @@ export class RiotAccountEnrichmentService {
|
||||
).exec();
|
||||
}
|
||||
|
||||
public async refreshRiotIdentity(params: {
|
||||
userId: mongoose.Types.ObjectId;
|
||||
puuid: string;
|
||||
region?: RiotRegionalRoute;
|
||||
}): Promise<RefreshRiotIdentityResult> {
|
||||
try {
|
||||
const UserModel = await this.connectionService.getModel('user');
|
||||
const user = await UserModel.findById(params.userId).exec();
|
||||
if (!user) return 'failed';
|
||||
|
||||
const account = user.riotAccounts.find(
|
||||
(candidate) => candidate.puuid === params.puuid,
|
||||
);
|
||||
if (!account) return 'failed';
|
||||
|
||||
const identity = await this.accountService.getByPuuid(params.puuid, {
|
||||
region: params.region ?? DEFAULT_REGION,
|
||||
});
|
||||
if (
|
||||
identity.puuid !== params.puuid ||
|
||||
!identity.gameName?.trim() ||
|
||||
!identity.tagLine?.trim()
|
||||
) {
|
||||
this.logger.warn(
|
||||
`Riot identity response was incomplete or mismatched for ${params.puuid}.`,
|
||||
);
|
||||
return 'failed';
|
||||
}
|
||||
|
||||
if (
|
||||
account.gameName === identity.gameName &&
|
||||
account.tagLine === identity.tagLine
|
||||
) {
|
||||
return 'unchanged';
|
||||
}
|
||||
|
||||
account.gameName = identity.gameName;
|
||||
account.tagLine = identity.tagLine;
|
||||
await user.save();
|
||||
return 'updated';
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`Riot identity refresh failed for ${params.puuid}: ${
|
||||
error instanceof Error ? error.message : String(error)
|
||||
}`,
|
||||
);
|
||||
return 'failed';
|
||||
}
|
||||
}
|
||||
|
||||
public async enrichRiotAccount(params: {
|
||||
userId: mongoose.Types.ObjectId;
|
||||
puuid: string;
|
||||
|
||||
Reference in new issue
Block a user