Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format code with prettier #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions serve/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class Store {
await fs.writeFile(questionFilePath, JSON.stringify(questions, null, 4));
console.log(`已将${surveyName}的问题列表保存至 ${questionFilePath} 文件中`); // 控制台输出提示信息
return {
code : 0,
code: 0,
message: '设置成功',
data : '问题列表已更新!'
data: '问题列表已更新!',
};
}

Expand Down Expand Up @@ -141,10 +141,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 };
})
}),
);
}
}
Expand Down
56 changes: 28 additions & 28 deletions serve/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class Survey {
async save(data: Omit<SurveyData, 'id' | 'createdAt'>): Promise<Response<SurveyData>> {
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,
};
}

Expand All @@ -66,9 +66,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), // 根据创建时间倒序排序
};
}

Expand All @@ -84,16 +84,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,
};
}
}
Expand All @@ -108,16 +108,16 @@ class Survey {
async setQuestions(questions: any[], surveyName: string): Promise<Response> {
if (!questions || !Array.isArray(questions)) {
return {
code : 400,
code: 400,
message: '参数错误',
data : '请提供正确的问题列表'
data: '请提供正确的问题列表',
};
}
await this.store.saveQuestions(questions, surveyName);
return {
code : 0,
code: 0,
message: '设置成功',
data : '问题列表已更新!'
data: '问题列表已更新!',
};
}

Expand All @@ -129,9 +129,9 @@ class Survey {
const questions = await this.store.readQuestions();
console.log(`查询到 ${questions.length} 条问题`);
return {
code : 0,
code: 0,
message: '查询成功',
data : questions
data: questions,
};
}

Expand All @@ -155,15 +155,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,
};
}
}
Expand All @@ -188,16 +188,16 @@ class Authorization {
async setRole(userId: string, role: string): Promise<Response<string>> {
if (!userId || !role) {
return {
code : 400,
code: 400,
message: '缺少参数',
data : '请提供正确的用户id和角色'
data: '请提供正确的用户id和角色',
};
}
this.authorizationMap[userId] = role;
return {
code : 0,
code: 0,
message: '设置成功',
data : '用户角色已更新!'
data: '用户角色已更新!',
};
}

Expand All @@ -209,16 +209,16 @@ class Authorization {
async getRole(userId: string): Promise<Response<string>> {
if (!userId) {
return {
code : 400,
code: 400,
message: '缺少参数',
data : '请提供正确的用户id'
data: '请提供正确的用户id',
};
}
const role = this.authorizationMap[userId] ?? '';
return {
code : 0,
code: 0,
message: '查询成功',
data : role
data: role,
};
}
}
Expand Down