rht
This commit is contained in:
parent
17cf2f77af
commit
4887a7f78e
|
@ -15,7 +15,7 @@ interface AgeRange {
|
|||
label: string;
|
||||
}
|
||||
interface Record {
|
||||
[key: string]: number[];
|
||||
[key: number]: number[];
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
|
|
|
@ -10,7 +10,7 @@ interface AgeRange {
|
|||
label: string;
|
||||
}
|
||||
interface Record {
|
||||
[key: string]: number[];
|
||||
[key: number]: number[];
|
||||
}
|
||||
interface ScoreStandard {
|
||||
ageRanges: AgeRange[];
|
||||
|
@ -20,7 +20,7 @@ interface ScoreStandard {
|
|||
@Injectable()
|
||||
export class SportStandardService extends BaseService<Prisma.SportStandardDelegate> {
|
||||
constructor() {
|
||||
super(db, ObjectType.SPORT_STANDARD, true);
|
||||
super(db, ObjectType.SPORT_STANDARD, false);
|
||||
}
|
||||
async create(args: Prisma.SportStandardCreateArgs) {
|
||||
console.log(args)
|
||||
|
@ -64,9 +64,10 @@ export class SportStandardService extends BaseService<Prisma.SportStandardDelega
|
|||
select?: Prisma.SportStandardSelect<DefaultArgs>,
|
||||
include?: Prisma.SportStandardInclude<DefaultArgs>
|
||||
) {
|
||||
console.log(data)
|
||||
this.validateAgeRanges(data.ageRanges);
|
||||
this.validateScoreTable(data.scoreTable, data.ageRanges.length);
|
||||
return this.create({
|
||||
const result = await super.create({
|
||||
data: {
|
||||
projectId: data.projectId,
|
||||
gender: data.gender,
|
||||
|
@ -77,6 +78,8 @@ export class SportStandardService extends BaseService<Prisma.SportStandardDelega
|
|||
select,
|
||||
include
|
||||
})
|
||||
this.emitDataChanged(CrudOperation.CREATED, result)
|
||||
return result
|
||||
}
|
||||
private validateAgeRanges(ranges: AgeRange[]) {
|
||||
// 检查年龄段是否按顺序排列且无重叠
|
||||
|
|
|
@ -3,22 +3,31 @@ import { api } from "@nice/client"
|
|||
import React from "react"
|
||||
import { useSport } from "@nice/client"
|
||||
export default function Dashboard() {
|
||||
// const {createSportProject} = useSport()
|
||||
// const handleCreateSportProject = () => {
|
||||
// createSportProject.mutate({
|
||||
// data:{
|
||||
// name:"测试项目",
|
||||
// description:"测试项目描述",
|
||||
// type:"测试类型",
|
||||
// unit:"测试单位",
|
||||
// isAscending:true
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
const { createSportStandard } = useSport()
|
||||
const handleCreateSportStandard = async () => {
|
||||
await createSportStandard.mutateAsync({
|
||||
data: {
|
||||
projectId: "cm8nsk1c0000czg9ix8d4yzml",
|
||||
gender: true,
|
||||
personType: "学生",
|
||||
ageRanges: [
|
||||
{ start: null, end: 24, label: "24岁以下" },
|
||||
{ start: 24, end: 27, label: "25-27岁" },
|
||||
{ start: 27, end: 30, label: "28-30岁" },
|
||||
{ start: 30, end: null, label: "30岁以上" }
|
||||
],
|
||||
scoreTable: {
|
||||
"100": [85, 81, 79, 77],
|
||||
"95": [74, 70, 68, 66],
|
||||
"90": [65, 61, 59, 57]
|
||||
}
|
||||
}
|
||||
} as any)
|
||||
}
|
||||
return (
|
||||
<div >
|
||||
数据看板(待开发)
|
||||
{/* <Button type="primary" onClick={()=>handleCreateSportProject()}>创建体育项目</Button> */}
|
||||
<Button type="primary" onClick={() => handleCreateSportStandard()}>创建体育项目</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -1,31 +1,33 @@
|
|||
import { getQueryKey } from "@trpc/react-query";
|
||||
import { api } from "../trpc"; // Adjust path as necessary
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { api, RouterOutputs } from "../trpc"; // Adjust path as necessary
|
||||
import { useQueryClient, UseMutationResult } from "@tanstack/react-query";
|
||||
import { ObjectType } from "@nice/common";
|
||||
import { CrudOperation, emitDataChange } from "../../event";
|
||||
|
||||
export function useSport() {
|
||||
interface SportOperation {
|
||||
createSportProject: UseMutationResult<RouterOutputs["sportProject"]["create"], Error, Parameters<typeof api.sportProject.create.useMutation>[0], unknown>;
|
||||
createSportStandard: UseMutationResult<RouterOutputs["sportStandard"]["createStandard"], Error, Parameters<typeof api.sportStandard.createStandard.useMutation<RouterOutputs["sportStandard"]["createStandard"]>>[0], unknown>;
|
||||
}
|
||||
export function useSport(): SportOperation {
|
||||
const queryClient = useQueryClient();
|
||||
const queryKey = getQueryKey(api.sportProject);
|
||||
const queryKeyStandard = getQueryKey(api.sportStandard);
|
||||
const queryKeyStandard = getQueryKey(api.sportStandard.createStandard);
|
||||
|
||||
const createSportProject = api.sportProject.create.useMutation({
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
emitDataChange(ObjectType.SPORT_PROJECT, result, CrudOperation.CREATED);
|
||||
},
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
emitDataChange(ObjectType.SPORT_PROJECT, result, CrudOperation.CREATED);
|
||||
},
|
||||
});
|
||||
|
||||
const createSportStandard = api.sportStandard.createStandard.useMutation({
|
||||
const createSportStandard = api.sportStandard.createStandard.useMutation<RouterOutputs["sportStandard"]["createStandard"]>({
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeyStandard });
|
||||
emitDataChange(ObjectType.SPORT_STANDARD, result, CrudOperation.CREATED);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
createSportProject,
|
||||
//createSportStandard
|
||||
createSportProject: createSportProject as any as UseMutationResult<RouterOutputs["sportProject"]["create"], Error, Parameters<typeof api.sportProject.create.useMutation>[0], unknown>,
|
||||
createSportStandard: createSportStandard as any as UseMutationResult<RouterOutputs["sportStandard"]["createStandard"], Error, Parameters<typeof api.sportStandard.createStandard.useMutation<RouterOutputs["sportStandard"]["createStandard"]>>[0], unknown>,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue