From b41612eee0c3ea72ddca37171177f8d3d919e741 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 17 May 2023 14:27:14 +0000 Subject: [PATCH] style: format code with prettier Format code with prettier This commit fixes the style issues introduced in bbd576d according to the output from prettier. Details: https://app.deepsource.com/gh/School-of-Website-Engineering/CollectX-Display-System/transform/e5659542-81f9-4cb1-8ccc-4ee8312ea6dc/ --- serve/src/api.ts | 12 ++++++------ serve/src/store.ts | 12 ++++++------ serve/src/survey.ts | 38 +++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/serve/src/api.ts b/serve/src/api.ts index 92f6d21..a32bff9 100644 --- a/serve/src/api.ts +++ b/serve/src/api.ts @@ -13,7 +13,7 @@ app.use(bodyParser.json()); * @apiGroup Survey 问卷调查 * @apiVersion 0.1.1 */ -app.post('/survey', async(req: Request, res: Response) => { +app.post('/survey', async (req: Request, res: Response) => { const { name, age, gender, surveyResult } = req.body; if (!name || !age || !gender || !surveyResult) { // 如果请求参数不完整,则返回错误信息 @@ -31,7 +31,7 @@ app.post('/survey', async(req: Request, res: Response) => { * @apiGroup Survey 问卷调查 * @apiVersion 0.1.0 */ -app.get('/survey', async(_req: Request, res: Response) => { +app.get('/survey', async (_req: Request, res: Response) => { const data = await survey.list(); // 查询数据 console.log(`查询到 ${data.data.length} 条问卷调查数据`); // 控制台输出提示信息 res.json(data); @@ -43,7 +43,7 @@ app.get('/survey', async(_req: Request, res: Response) => { * @apiGroup Survey 问卷调查 * @apiVersion 0.1.0 */ -app.get('/survey/question/:id', async(req: Request, res: Response) => { +app.get('/survey/question/:id', async (req: Request, res: Response) => { const data = await survey.findById(req.params.id); // 根据 ID 查询数据 console.log(`查询问卷调查数据,id 为 ${req.params.id}`); // 控制台输出提示信息 res.status(data.code).json(data); @@ -55,7 +55,7 @@ app.get('/survey/question/:id', async(req: Request, res: Response) => { * @apiGroup Survey 问卷调查 * @apiVersion 0.2.0 */ -app.get('/survey/questions', async(req: Request, res: Response>) => { +app.get('/survey/questions', async (req: Request, res: Response>) => { const result = await survey.getQuestions(); res.json(result); }); @@ -69,7 +69,7 @@ app.get('/survey/questions', async(req: Request, res: Response>) = * "surveyName": "2020年度问卷调查" *} */ -app.get('/survey/data', async(req: Request, res: Response>) => { +app.get('/survey/data', async (req: Request, res: Response>) => { const { surveyName } = req.body; const result = await survey.querySurveyData(surveyName); res.json(result); @@ -90,7 +90,7 @@ app.get('/survey/data', async(req: Request, res: Response>) => { * "userName": "张三" * } */ -app.post('/survey/questions', async(req: Request, res: Response) => { +app.post('/survey/questions', async (req: Request, res: Response) => { const { questions, surveyName, userName } = req.body; const result = await survey.setQuestions(questions, surveyName, userName); res.json(result); diff --git a/serve/src/store.ts b/serve/src/store.ts index c61d480..644bedf 100644 --- a/serve/src/store.ts +++ b/serve/src/store.ts @@ -123,10 +123,10 @@ class Store { const regex = new RegExp(`^${surveyName}_data_`); const dataFiles = files.filter((file) => regex.test(file)); return Promise.all( - dataFiles.map(async(file) => { + dataFiles.map(async (file) => { const data = await this.findByFileName(file); return { ...data, id: file }; - }) + }), ); } @@ -141,9 +141,9 @@ class Store { public async saveQuestions(questions: string[], surveyName: string, userName: string): Promise { // 设置创建时间与id const newQuestion = { - id : uuidv4(), + id: uuidv4(), createTime: new Date().toISOString(), - questions + questions, }; // 根据用户名创建文件夹,文件夹里存放该用户创建的调查问卷 const userDir = path.resolve(__dirname, `data/${userName}`); @@ -154,9 +154,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 fbaa330..5c114ae 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,15 +119,15 @@ class Survey { console.log(`查询${surveyName}调查问卷数据,共${data.length}条`); if (data.length === 0) { return { - code : 404, + code: 404, message: '数据不存在', - data : [] + data: [], }; } return { - code : 0, + code: 0, message: '查询成功', - data + data, }; } @@ -142,14 +142,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, }; }