Skip to content

Commit 3ca8de3

Browse files
committed
feat: stats endpoints
1 parent 2d7c28e commit 3ca8de3

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/realms/rest/endpoints/controllers/Player.controller.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,10 @@ export default class PlayerController {
396396
req.params.statKey,
397397
req.body.value,
398398
req.body.reason,
399-
req.query.set
399+
req.query.set,
400+
req.body.type,
401+
req.body.displayName,
402+
req.body.color
400403
)
401404
return reply.code(204).send()
402405
}

src/realms/rest/endpoints/schemas/Player.schema.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FastifySchema } from "fastify"
22
import { Static, Type } from "@sinclair/typebox"
33
import PlayerSchema from "../../schemas/Player.schema"
4-
import { ApiScope, ChatChannels } from "@prisma/client"
4+
import { ApiScope, ChatChannels, StatisticType } from "@prisma/client"
55
import PermissionSchema from "../../schemas/Permission.schema"
66
import PermissionInputSchema from "../../schemas/PermissionInput.schema"
77
import PlayerStatisticRecordSchema from "../../schemas/PlayerStatisticRecord.schema"
@@ -382,7 +382,11 @@ export type PlayerStatParamsSchema = Static<typeof PlayerStatParamsSchema>
382382

383383
const PlayerStatManageBodySchema = Type.Object({
384384
value: Type.Number(),
385-
reason: Type.Optional(Type.String())
385+
reason: Type.Optional(Type.String()),
386+
387+
type: Type.Optional(Type.Enum(StatisticType)),
388+
displayName: Type.Optional(Type.String()),
389+
color: Type.Optional(Type.String())
386390
})
387391

388392
export type PlayerStatManageBodySchema = Static<

src/realms/rest/endpoints/services/Player.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,11 @@ export default class PlayerService {
681681
key: string,
682682
value: number,
683683
reason: string,
684-
set = false
685-
): Promise<void> {
684+
set = false,
685+
type?: StatisticType,
686+
displayName?: string,
687+
color?: string
688+
) {
686689
let stat = await prisma.statistic.findUnique({
687690
where: {
688691
key
@@ -700,7 +703,10 @@ export default class PlayerService {
700703
if (!stat) {
701704
stat = await prisma.statistic.create({
702705
data: {
703-
key
706+
key,
707+
type,
708+
displayName,
709+
color
704710
},
705711
select: {
706712
type: true,

0 commit comments

Comments
 (0)