mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Update sendUserChanges to make the settings system work.
This commit is contained in:
parent
ad0f13a1a2
commit
85c3332c76
3 changed files with 23 additions and 16 deletions
|
@ -12,23 +12,26 @@ export default defineEventHandler(async (event) => {
|
|||
const body = await readBody(event);
|
||||
if (body.jsonValue.length === 0) {
|
||||
const clearBadDataRegex = /[@-_.+a-zA-Z0-9]{2,}/;
|
||||
let allowed = true;
|
||||
if (body.value.match()) {
|
||||
allowed = false;
|
||||
}
|
||||
// Use Static values for now.
|
||||
const requestChange = "groq_api_key";
|
||||
const requestChange = body.name;
|
||||
const apiKeyqq = body.value.match(clearBadDataRegex);
|
||||
const allowedColumns = ["groq_api_key", "another_column_name"];
|
||||
const allowedColumns = ["firstname", "email"];
|
||||
|
||||
if (!allowedColumns.includes(requestChange)) {
|
||||
throw new Error("Invalid column name provided");
|
||||
return {
|
||||
error: "ERR_NOT_ALLOWED",
|
||||
};
|
||||
} else if (requestChange === "name") {
|
||||
const sqlC = await sql`
|
||||
UPDATE users SET firstname = ${apiKeyqq[0]}
|
||||
WHERE username = ${token.user}`;
|
||||
return {
|
||||
sqlC: sqlC,
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
const sqlC = await sql.unsafe(
|
||||
`
|
||||
UPDATE user_other_data SET ${requestChange} = $1
|
||||
WHERE username = $2`,
|
||||
`UPDATE user_other_data SET ${requestChange} = $1 WHERE username = $2`,
|
||||
[apiKeyqq[0], token.user],
|
||||
);
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue