diff --git a/serve/src/store.ts b/serve/src/store.ts index d84faf4..059c98f 100644 --- a/serve/src/store.ts +++ b/serve/src/store.ts @@ -138,10 +138,10 @@ class Store { public async saveQuestions(questions: string[], surveyName: string, userName: string): Promise { // 设置创建时间与id const newQuestion = { - id : uuidv4(), + id: uuidv4(), createTime: new Date().toISOString(), surveyName, - questions + questions, }; // 根据用户名创建文件夹,文件夹里存放该用户创建的调查问卷 const userDir = path.resolve(__dirname, `data/${userName}`); @@ -152,9 +152,9 @@ class Store { console.log(`已将提问者 ${userName} 的问题列表${surveyName}_question.json保存至 ${filePath} 文件中`); return { - code : 0, + code: 0, message: '设置成功,问题列表已更新', - data : newQuestion + data: newQuestion, }; } } diff --git a/serve/src/survey.ts b/serve/src/survey.ts index 2b5b5f6..55c06fb 100644 --- a/serve/src/survey.ts +++ b/serve/src/survey.ts @@ -41,15 +41,15 @@ class Survey { async save(data: Omit): Promise> { const newData: SurveyData = { ...data, - id : uuidv4(), - createdAt: Date.now() + id: uuidv4(), + createdAt: Date.now(), }; // 生成新数据并保存 await this.store.save(newData); console.log(`已将问卷调查数据 ${JSON.stringify(newData)} 保存至文件`); // 控制台输出提示信息 return { - code : 0, + code: 0, message: '提交成功', - data : newData + data: newData, }; } @@ -63,9 +63,9 @@ class Survey { const data = await this.store.read(); // 从数据存储对象中读取数据 console.log(`查询到 ${data.length} 条问卷调查数据`); // 控制台输出提示信息 return { - code : 0, + code: 0, message: '查询成功', - data : data.sort((a, b) => b.createdAt - a.createdAt) // 根据创建时间倒序排序 + data: data.sort((a, b) => b.createdAt - a.createdAt), // 根据创建时间倒序排序 }; } @@ -81,16 +81,16 @@ class Survey { if (result) { console.log(`查询问卷调查数据,id 为 ${id} 的数据存在`); // 控制台输出提示信息 return { - code : 0, + code: 0, message: '查询成功', - data : result + data: result, }; } else { console.log(`查询问卷调查数据,id 为 ${id} 的数据不存在`); // 控制台输出提示信息 return { - code : 404, + code: 404, message: '数据不存在', - data : undefined + data: undefined, }; } } @@ -103,9 +103,9 @@ class Survey { const questions = await this.store.readQuestions(); console.log(`查询到 ${questions.length} 条问题`); return { - code : 0, + code: 0, message: '查询成功', - data : questions + data: questions, }; } @@ -119,16 +119,16 @@ class Survey { const data = (await this.store.querySurveyData(surveyName, userName)) as any; if (!data) { return { - code : 404, + code: 404, message: '数据不存在,请检查调查问卷名称', - data : [] + data: [], }; } console.log(`查询${surveyName}调查问卷数据,共${data.questions.length}条`); return { - code : 0, + code: 0, message: '查询成功', - data + data, }; } @@ -143,14 +143,14 @@ class Survey { async setQuestions(questions: any[], surveyName: string, userName: string): Promise { if (!questions || !Array.isArray(questions)) { return { - code : 400, + code: 400, message: '参数错误', - data : null + data: null, }; } const data = await this.store.saveQuestions(questions, surveyName, userName); return { - ...data + ...data, }; }