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