feat: 完成全部接口替换为新后端接口
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { managementRequest } from '../../services/admin-api';
|
||||
import { MOCK_SEED_COUNTS } from './mockLikes';
|
||||
import {
|
||||
MATH_WORKSHEET_DEFINITIONS,
|
||||
@@ -21,17 +22,6 @@ type CloudFunctionResult<T> = {
|
||||
results?: Array<{ id: string | null; ok: boolean; error?: string }>;
|
||||
};
|
||||
|
||||
async function callCloudFunction<T>(
|
||||
name: string,
|
||||
data?: Record<string, unknown>,
|
||||
): Promise<CloudFunctionResult<T>> {
|
||||
const response = (await wx.cloud.callFunction({
|
||||
name,
|
||||
data: data || {},
|
||||
})) as { result?: CloudFunctionResult<T> };
|
||||
return response.result || {};
|
||||
}
|
||||
|
||||
function inferGradeFromAge(ageMin: number, ageMax: number): number {
|
||||
const centerAge = Math.round((ageMin + ageMax) / 2);
|
||||
const ageGradeMap: Record<number, number> = {
|
||||
@@ -224,7 +214,7 @@ Page({
|
||||
const startedAt = Date.now();
|
||||
|
||||
try {
|
||||
const patchRes = await callCloudFunction('worksheetsBatchPatch', {
|
||||
const patchRes = await managementRequest('worksheets.batch', {
|
||||
patches,
|
||||
dryRun: false,
|
||||
});
|
||||
@@ -262,7 +252,7 @@ Page({
|
||||
const startedAt = Date.now();
|
||||
|
||||
try {
|
||||
const rebuildRes = await callCloudFunction('pageContentBuild', {
|
||||
const rebuildRes = await managementRequest('site.rebuild', {
|
||||
page: 'all',
|
||||
});
|
||||
const elapsed = Math.round((Date.now() - startedAt) / 1000);
|
||||
@@ -358,7 +348,7 @@ Page({
|
||||
}),
|
||||
);
|
||||
|
||||
const patchRes = await callCloudFunction('worksheetsBatchPatch', {
|
||||
const patchRes = await managementRequest('worksheets.batch', {
|
||||
patches,
|
||||
dryRun: false,
|
||||
});
|
||||
@@ -415,8 +405,8 @@ Page({
|
||||
const startedAt = Date.now();
|
||||
|
||||
try {
|
||||
const queryRes = await callCloudFunction<Array<{ _id: string }>>(
|
||||
'worksheetsQuery',
|
||||
const queryRes = await managementRequest<Array<{ _id: string }>>(
|
||||
'worksheets.list',
|
||||
{},
|
||||
);
|
||||
|
||||
@@ -438,7 +428,7 @@ Page({
|
||||
return;
|
||||
}
|
||||
|
||||
const patchRes = await callCloudFunction('worksheetsBatchPatch', {
|
||||
const patchRes = await managementRequest('worksheets.batch', {
|
||||
patches,
|
||||
dryRun: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user