Compare commits
No commits in common. "fe0bc8d8d7dc34cbb545665cb8c30949f12367e1" and "a79b1fe65083ec333e2aabed65e215af0875f137" have entirely different histories.
fe0bc8d8d7
...
a79b1fe650
|
|
@ -15,7 +15,7 @@ interface AgeRange {
|
||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
interface Record {
|
interface Record {
|
||||||
[key: number]: number[];
|
[key: string]: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ interface AgeRange {
|
||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
interface Record {
|
interface Record {
|
||||||
[key: number]: number[];
|
[key: string]: 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, false);
|
super(db, ObjectType.SPORT_STANDARD, true);
|
||||||
}
|
}
|
||||||
async create(args: Prisma.SportStandardCreateArgs) {
|
async create(args: Prisma.SportStandardCreateArgs) {
|
||||||
console.log(args)
|
console.log(args)
|
||||||
|
|
@ -64,10 +64,9 @@ 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);
|
||||||
const result = await super.create({
|
return this.create({
|
||||||
data: {
|
data: {
|
||||||
projectId: data.projectId,
|
projectId: data.projectId,
|
||||||
gender: data.gender,
|
gender: data.gender,
|
||||||
|
|
@ -78,8 +77,6 @@ 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,31 +3,22 @@ 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 { createSportStandard } = useSport()
|
// const {createSportProject} = useSport()
|
||||||
const handleCreateSportStandard = async () => {
|
// const handleCreateSportProject = () => {
|
||||||
await createSportStandard.mutateAsync({
|
// createSportProject.mutate({
|
||||||
data: {
|
// data:{
|
||||||
projectId: "cm8nsk1c0000czg9ix8d4yzml",
|
// name:"测试项目",
|
||||||
gender: true,
|
// description:"测试项目描述",
|
||||||
personType: "学生",
|
// type:"测试类型",
|
||||||
ageRanges: [
|
// unit:"测试单位",
|
||||||
{ start: null, end: 24, label: "24岁以下" },
|
// isAscending:true
|
||||||
{ 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={() => handleCreateSportStandard()}>创建体育项目</Button>
|
{/* <Button type="primary" onClick={()=>handleCreateSportProject()}>创建体育项目</Button> */}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1,33 +1,31 @@
|
||||||
import { getQueryKey } from "@trpc/react-query";
|
import { getQueryKey } from "@trpc/react-query";
|
||||||
import { api, RouterOutputs } from "../trpc"; // Adjust path as necessary
|
import { api } from "../trpc"; // Adjust path as necessary
|
||||||
import { useQueryClient, UseMutationResult } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { ObjectType } from "@nice/common";
|
import { ObjectType } from "@nice/common";
|
||||||
import { CrudOperation, emitDataChange } from "../../event";
|
import { CrudOperation, emitDataChange } from "../../event";
|
||||||
|
|
||||||
interface SportOperation {
|
export function useSport() {
|
||||||
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.createStandard);
|
const queryKeyStandard = getQueryKey(api.sportStandard);
|
||||||
|
|
||||||
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({
|
||||||
|
// onSuccess: (result) => {
|
||||||
|
// queryClient.invalidateQueries({ queryKey: queryKeyStandard });
|
||||||
|
// emitDataChange(ObjectType.SPORT_STANDARD, result, CrudOperation.CREATED);
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
const createSportStandard = api.sportStandard.createStandard.useMutation<RouterOutputs["sportStandard"]["createStandard"]>({
|
|
||||||
onSuccess: (result) => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: queryKeyStandard });
|
|
||||||
emitDataChange(ObjectType.SPORT_STANDARD, result, CrudOperation.CREATED);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
createSportProject: createSportProject as any as UseMutationResult<RouterOutputs["sportProject"]["create"], Error, Parameters<typeof api.sportProject.create.useMutation>[0], unknown>,
|
createSportProject,
|
||||||
createSportStandard: createSportStandard as any as UseMutationResult<RouterOutputs["sportStandard"]["createStandard"], Error, Parameters<typeof api.sportStandard.createStandard.useMutation<RouterOutputs["sportStandard"]["createStandard"]>>[0], unknown>,
|
//createSportStandard
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue