-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { router } from "../trpc"; | ||
|
||
export const appEnvRouter = router({ | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,65 @@ | ||
import { z } from 'zod'; | ||
import { prisma } from '../../prisma/prisma.service'; | ||
import { procedure, router } from '../trpc'; | ||
import { ApplicationZod } from '../types/zod'; | ||
import { addApplication, deleteApplicationById, getApplicationList, updateApplicationById } from '../service/application'; | ||
import { ApplicationCreateZod, ApplicationUpdateZod } from '../types/zodExt/Application'; | ||
import { getDefaultFailResponse, getDefaultPageResponse, getDefaultResponse } from '../utils'; | ||
import { ApiPageResponseZod, ApiResponseZod, PageInfoQueryZod } from '../types'; | ||
|
||
export const applicationRouter = router({ | ||
/** 获取应用列表 */ | ||
pageList: procedure | ||
/** 新增应用 */ | ||
addRecord: procedure | ||
.meta({ | ||
description: "获取应用列表" | ||
description: "新增应用" | ||
}) | ||
.output(z.array(ApplicationZod)) | ||
.input(ApplicationCreateZod) | ||
.mutation(async ({ input }) => { | ||
const res = await addApplication(input); | ||
if (res?.id) return getDefaultResponse(); | ||
return getDefaultFailResponse(); | ||
}), | ||
/** 根据id删除应用 */ | ||
deleteRecodeById: procedure | ||
.meta({ | ||
description: "删除应用" | ||
}) | ||
.input(ApplicationZod.pick({ id: true })) | ||
.mutation(async ({ input }) => { | ||
const res = await deleteApplicationById(input.id); | ||
if (res.id === input.id) return getDefaultResponse(); | ||
return getDefaultFailResponse(); | ||
}), | ||
/** 获取全部应用列表 */ | ||
getList: procedure | ||
.meta({ | ||
description: "获取全部应用列表" | ||
}) | ||
.output(ApiResponseZod(z.array(ApplicationZod))) | ||
.query(async () => { | ||
const list = await prisma.application.findMany({ | ||
where: { | ||
isDeleted: false | ||
} | ||
}); | ||
return list; | ||
const list = await getApplicationList(); | ||
return getDefaultResponse(list); | ||
}), | ||
/** 分页获取应用列表 */ | ||
getListByPage: procedure | ||
.meta({ | ||
description: "分页获取应用列表" | ||
}) | ||
.input(PageInfoQueryZod) | ||
.output(ApiPageResponseZod(ApplicationZod)) | ||
.query(async ({ input }) => { | ||
const list = await getApplicationList(); | ||
return getDefaultPageResponse(input, list, 1000); | ||
}), | ||
/** 更新应用信息 */ | ||
updateRecord: procedure | ||
.meta({ | ||
description: '更新应用信息' | ||
}) | ||
.input(ApplicationUpdateZod) | ||
.output(ApiResponseZod()) | ||
.mutation(async ({ input }) => { | ||
const res = await updateApplicationById(input); | ||
if (res.id == input.id) return getDefaultResponse(); | ||
return getDefaultFailResponse(); | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { prisma } from "../../prisma/prisma.service"; | ||
import { ApplicationCreateDto, ApplicationUpdateDto } from "../types/zodExt/Application"; | ||
|
||
export async function addApplication(data: ApplicationCreateDto) { | ||
return await prisma.$transaction(async (mysql) => { | ||
const res = await mysql.application.create({ data }); | ||
if (!res.id) return; | ||
/** | ||
* 应用默认版本1.0.0 | ||
*/ | ||
const versionData = { | ||
applicationId: res.id, | ||
version: '1.0.0', | ||
isAuditing: false, | ||
isPass: false, | ||
auditContent: '', | ||
isDeleted: false | ||
}; | ||
const res_version = await mysql.appVersion.create({ data: versionData}); | ||
/** | ||
* 应用默认环境test、pre、master | ||
*/ | ||
const envData = { | ||
applicationId: res.id, | ||
env: 'test', | ||
envCh: '测试', | ||
canDelete: false, | ||
appVersionId: res_version.id, | ||
version: '1.0.0', | ||
isDeleted: false | ||
}; | ||
await mysql.appEnv.create({ data: envData }); | ||
envData.env = 'pre'; | ||
envData.envCh = '预发'; | ||
await mysql.appEnv.create({ data: envData }); | ||
envData.env = 'master'; | ||
envData.envCh = '正式'; | ||
envData.appVersionId = 0; // 正式环境不绑定版本! | ||
envData.version = ''; // 正式环境须审核通过才能绑定! | ||
await mysql.appEnv.create({ data: envData }); | ||
const pageNode = { | ||
name: 'root', | ||
nameCh: '根节点', | ||
describe: '根节点, 有且唯一', | ||
applicationId: res.id, | ||
version: '1.0.0' | ||
}; | ||
return await mysql.pageNode.create({ | ||
data: pageNode | ||
}); | ||
}) | ||
} | ||
|
||
export async function deleteApplicationById(id: number) { | ||
const res = await prisma.application.update({ | ||
where: { id }, | ||
data: { | ||
isDeleted: true | ||
} | ||
}) | ||
console.log(res); | ||
return res; | ||
} | ||
|
||
export async function getApplicationList() { | ||
return await prisma.application.findMany({ | ||
where: { | ||
isDeleted: false, | ||
} | ||
}) | ||
} | ||
|
||
export async function getPageList() { | ||
return await prisma.application.findMany({ | ||
where: { | ||
isDeleted: false, | ||
} | ||
}) | ||
} | ||
|
||
export async function updateApplicationById(data: ApplicationUpdateDto) { | ||
return await prisma.application.update({ | ||
where: { | ||
id: data.id | ||
}, | ||
data: { | ||
name: data.name, | ||
describe: data.describe | ||
} | ||
}) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import { z } from "zod"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { z } from "zod"; | ||
import { ApplicationZod } from "../zod/Application"; | ||
|
||
export const ApplicationCreateZod = ApplicationZod.pick({ | ||
name: true, | ||
describe: true, | ||
}); | ||
|
||
export type ApplicationCreateDto = z.infer<typeof ApplicationCreateZod>; | ||
|
||
export const ApplicationUpdateZod = ApplicationZod.pick({ | ||
id: true, | ||
name: true, | ||
describe: true, | ||
}); | ||
|
||
export type ApplicationUpdateDto = z.infer<typeof ApplicationUpdateZod>; | ||
|