feat: prefix and anti multi-check
This commit is contained in:
@@ -22,25 +22,35 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
count += 1;
|
||||
if (count >= config.limit) {
|
||||
res.status(403).json({
|
||||
error: `超过选择数量限制,您至多选 ${config.limit} 个班.`,
|
||||
error: `超过选择数量限制,您至多选 ${config.limit} 个班次`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check whether it is already occupied
|
||||
if (store[json.name] !== undefined) {
|
||||
// check whether the user repeatly select
|
||||
if (store[json.name] === json.user) {
|
||||
console.log("api::request: repeat select", json);
|
||||
res.status(403).json({
|
||||
error: `当前位置已被他人占用`,
|
||||
error: `您已经选择了这个班次,请勿重复选择`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// check whether it is already occupied
|
||||
else if (store[json.name] !== undefined) {
|
||||
console.log("api::request: occupied", json);
|
||||
res.status(403).json({
|
||||
error: `当前位置已被他人占用,请选择其他班次`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
store[json.name] = json.user;
|
||||
} else {
|
||||
// console.log(store, json);
|
||||
// check whether the request name match the taken name
|
||||
if (store[json.name] !== json.user) {
|
||||
res.status(403).json({
|
||||
error: `失败:您未选择到当前位置`,
|
||||
error: `您已经取消了这个班次,请勿重复点击复选框`,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user