Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion open-api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@
"type": "string"
},
"individualReason": {
"type": "string"
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/schema/components/InstanceStanding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const zInstancePlayerStanding = registry.register(
instanceId: zInt64(),
instanceDate: zISODateString(),
reason: z.string(),
individualReason: z.string(),
individualReason: z.string().nullable(),
createdAt: zISODateString()
})
),
Expand Down
15 changes: 15 additions & 0 deletions src/services/reporting/standing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ describe("getInstancePlayersStanding", () => {
expect(parsed.success).toBe(true)
}
})

it("returns the correct shape #2", async () => {
const standing = await getInstancePlayersStanding("16327328028")
expect(standing.length).toBe(6)
expect(standing[1].playerInfo.membershipId).toBe("4611686018470558748")
expect(standing[1].blacklistedInstances.length).toBeGreaterThan(0)

const parsed = z.array(zInstancePlayerStanding).safeParse(standing)
if (!parsed.success) {
console.error(parsed.error.errors)
expect(parsed.error.errors).toEqual([])
} else {
expect(parsed.success).toBe(true)
}
})
})
25 changes: 13 additions & 12 deletions src/services/reporting/standing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,32 @@ export const getInstancePlayersStanding = async (instanceId: bigint | string) =>
'flaggedAt', fip.flagged_at
) AS "data"
FROM flag_instance_player fip
JOIN instance i ON i.instance_id = fip.instance_id
JOIN instance i USING (instance_id)
WHERE fip.membership_id = p.membership_id
AND fip.instance_id <> $1::bigint
ORDER BY date_trunc('week', fip.flagged_at) DESC, fip.cheat_probability DESC
LIMIT 10
ORDER BY (fip.cheat_probability - EXTRACT(EPOCH FROM (NOW() - i.date_started)) / 86400 / 365) DESC
LIMIT 15
) AS f
) AS "otherRecentFlags",
(
SELECT COALESCE(jsonb_agg(b.data), '[]'::jsonb)
FROM (
SELECT json_build_object(
'instanceId', bip.instance_id,
'instanceId', bi.instance_id::text,
'individualReason', bip.reason,
'reason', bi.reason,
'createdAt', bi.created_at,
'instanceDate', i.date_started
) AS "data"
FROM blacklist_instance_player bip
JOIN instance i ON i.instance_id = bip.instance_id
JOIN blacklist_instance bi ON bi.instance_id = bip.instance_id
WHERE bip.membership_id = p.membership_id
AND bip.instance_id <> $1::bigint
AND i.date_started < NOW() - INTERVAL '6 months'
ORDER BY bip.instance_id DESC
LIMIT 10
FROM blacklist_instance bi
JOIN instance i ON i.instance_id = bi.instance_id
JOIN instance_player ip ON ip.instance_id = bi.instance_id AND ip.membership_id = p.membership_id
LEFT JOIN blacklist_instance_player bip ON bi.instance_id = bip.instance_id
AND bip.membership_id = p.membership_id
WHERE bi.instance_id <> $1::bigint
AND NOT (bi.report_source = 'BlacklistedPlayerCascade' AND bip.membership_id IS NOT NULL)
ORDER BY i.date_started DESC
LIMIT 15
) AS b
) AS "blacklistedInstances"
FROM instance_player ip
Expand Down
Loading