mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-08-26 04:40:33 -05:00
Merge pull request #326 from PretendoNetwork/feat/pnids-fetch-api
Feat: Implement GetPNIDs rpc & stub newer account v2 grpc methods
This commit is contained in:
1760
package-lock.json
generated
1760
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
75
src/services/grpc/account/v2/get-pnids.ts
Normal file
75
src/services/grpc/account/v2/get-pnids.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { getPNIDByPID } from '@/database';
|
||||
import { PNID_PERMISSION_FLAGS } from '@/types/common/permission-flags';
|
||||
import { config } from '@/config-manager';
|
||||
import { Device } from '@/models/device';
|
||||
import type { GetPNIDsRequest, GetPNIDsResponse } from '@pretendonetwork/grpc/account/v2/get_pnids_rpc';
|
||||
|
||||
export async function getPNIDs(request: GetPNIDsRequest): Promise<GetPNIDsResponse> {
|
||||
const response: GetPNIDsResponse = { userData: [] };
|
||||
for (const pid of request.pid) {
|
||||
const pnid = await getPNIDByPID(pid);
|
||||
if (!pnid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const devices = (await Device.find({
|
||||
linked_pids: pnid.pid
|
||||
})).map((device) => {
|
||||
return {
|
||||
model: device.get('model'), // ".model" gives the Mongoose model...
|
||||
serial: device.serial,
|
||||
linkedPids: device.linked_pids,
|
||||
accessLevel: device.access_level,
|
||||
serverAccessLevel: device.server_access_level,
|
||||
deviceId: device.device_id
|
||||
};
|
||||
});
|
||||
|
||||
response.userData[pid] = {
|
||||
deleted: pnid.deleted || pnid.marked_for_deletion,
|
||||
pid: pnid.pid,
|
||||
username: pnid.username,
|
||||
accessLevel: pnid.access_level,
|
||||
serverAccessLevel: pnid.server_access_level,
|
||||
mii: {
|
||||
name: pnid.mii.name,
|
||||
data: pnid.mii.data,
|
||||
url: `${config.cdn.base_url}/mii/${pnid.pid}/standard.tga`
|
||||
},
|
||||
creationDate: pnid.creation_date,
|
||||
birthdate: pnid.birthdate,
|
||||
gender: pnid.gender,
|
||||
country: pnid.country,
|
||||
language: pnid.language,
|
||||
emailAddress: pnid.email.address,
|
||||
tierName: pnid.connections.stripe.tier_name,
|
||||
permissions: {
|
||||
bannedAllPermanently: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_PERMANENTLY),
|
||||
bannedAllTemporarily: pnid.hasPermission(PNID_PERMISSION_FLAGS.BANNED_ALL_TEMPORARILY),
|
||||
betaAccess: pnid.hasPermission(PNID_PERMISSION_FLAGS.BETA_ACCESS),
|
||||
accessAdminPanel: pnid.hasPermission(PNID_PERMISSION_FLAGS.ACCESS_ADMIN_PANEL),
|
||||
createServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_SERVER_CONFIGS),
|
||||
modifyServerConfigs: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_SERVER_CONFIGS),
|
||||
deployServer: pnid.hasPermission(PNID_PERMISSION_FLAGS.DEPLOY_SERVER),
|
||||
modifyPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_PNIDS),
|
||||
modifyNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_NEX_ACCOUNTS),
|
||||
modifyConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODIFY_CONSOLES),
|
||||
banPnids: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_PNIDS),
|
||||
banNexAccounts: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_NEX_ACCOUNTS),
|
||||
banConsoles: pnid.hasPermission(PNID_PERMISSION_FLAGS.BAN_CONSOLES),
|
||||
moderateMiiverse: pnid.hasPermission(PNID_PERMISSION_FLAGS.MODERATE_MIIVERSE),
|
||||
createApiKeys: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_API_KEYS),
|
||||
createBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.CREATE_BOSS_TASKS),
|
||||
updateBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_TASKS),
|
||||
deleteBossTasks: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_TASKS),
|
||||
uploadBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPLOAD_BOSS_FILES),
|
||||
updateBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_BOSS_FILES),
|
||||
deleteBossFiles: pnid.hasPermission(PNID_PERMISSION_FLAGS.DELETE_BOSS_FILES),
|
||||
updatePnidPermissions: pnid.hasPermission(PNID_PERMISSION_FLAGS.UPDATE_PNID_PERMISSIONS)
|
||||
},
|
||||
linkedDevices: devices
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { getNEXData } from '@/services/grpc/account/v2/get-nex-data';
|
||||
import { updatePNIDPermissions } from '@/services/grpc/account/v2/update-pnid-permissions';
|
||||
import { exchangeTokenForUserData } from '@/services/grpc/account/v2/exchange-token-for-user-data';
|
||||
import { deleteAccount } from '@/services/grpc/account/v2/delete-account';
|
||||
import { getPNIDs } from '@/services/grpc/account/v2/get-pnids';
|
||||
import type { ServiceImplementation } from 'nice-grpc';
|
||||
import type { AccountServiceDefinition } from '@pretendonetwork/grpc/account/v2/account_service';
|
||||
|
||||
@@ -19,6 +20,7 @@ export const accountServiceImplementationV2: ServiceImplementation<AccountServic
|
||||
updatePNIDPermissions,
|
||||
exchangeTokenForUserData,
|
||||
deleteAccount,
|
||||
getPNIDs,
|
||||
|
||||
// The following methods are not yet implemented
|
||||
createAuditLogComment: notImplemented,
|
||||
@@ -35,7 +37,6 @@ export const accountServiceImplementationV2: ServiceImplementation<AccountServic
|
||||
getNEXAccount: notImplemented,
|
||||
getPNID: notImplemented,
|
||||
getServer: notImplemented,
|
||||
getPNIDs: notImplemented,
|
||||
issueBan: notImplemented,
|
||||
listAuditLogComments: notImplemented,
|
||||
listBans: notImplemented,
|
||||
|
||||
Reference in New Issue
Block a user