22
projects/app/src/pages/api/core/app/version/detail.ts
Normal file
22
projects/app/src/pages/api/core/app/version/detail.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
import { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
type Props = {
|
||||
versionId: string;
|
||||
appId: string;
|
||||
};
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
const { versionId, appId } = req.query as Props;
|
||||
|
||||
await authApp({ req, authToken: true, appId, per: ReadPermissionVal });
|
||||
const result = await MongoAppVersion.findById(versionId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
56
projects/app/src/pages/api/core/app/version/listWorkflow.tsx
Normal file
56
projects/app/src/pages/api/core/app/version/listWorkflow.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { MongoAppVersion } from '@fastgpt/service/core/app/version/schema';
|
||||
import { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type';
|
||||
|
||||
type Props = PaginationProps<{
|
||||
appId: string;
|
||||
}>;
|
||||
|
||||
export type versionListResponse = {
|
||||
_id: string;
|
||||
appId: string;
|
||||
versionName: string;
|
||||
time: Date;
|
||||
isPublish: boolean | undefined;
|
||||
tmbId: string;
|
||||
};
|
||||
|
||||
type Response = PaginationResponse<versionListResponse>;
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse<any>): Promise<Response> {
|
||||
const { current, pageSize, appId } = req.body as Props;
|
||||
|
||||
const [result, total] = await Promise.all([
|
||||
MongoAppVersion.find(
|
||||
{
|
||||
appId
|
||||
},
|
||||
'_id appId versionName time isPublish tmbId'
|
||||
)
|
||||
.sort({
|
||||
time: -1
|
||||
})
|
||||
.skip((current - 1) * pageSize)
|
||||
.limit(pageSize),
|
||||
MongoAppVersion.countDocuments({ appId })
|
||||
]);
|
||||
|
||||
const versionList = result.map((item) => {
|
||||
return {
|
||||
_id: item._id,
|
||||
appId: item.appId,
|
||||
versionName: item.versionName,
|
||||
time: item.time,
|
||||
isPublish: item.isPublish,
|
||||
tmbId: item.tmbId
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
total,
|
||||
list: versionList
|
||||
};
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
Reference in New Issue
Block a user