mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Update some code & made a basic isThis ArticleStarred api? & starring is
now a wip!
This commit is contained in:
parent
026c4a31a3
commit
2cf787a401
4 changed files with 75 additions and 1 deletions
30
server/api/user/[slug]/isThisArticleStarred.ts
Normal file
30
server/api/user/[slug]/isThisArticleStarred.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
import getUserTokenMinusSQLInjection from "~/server/components/getUserToken";
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const token = await getUserTokenMinusSQLInjection(event);
|
||||
if (token.error.length !== 0) {
|
||||
return {
|
||||
error: token.error,
|
||||
};
|
||||
}
|
||||
const getOtherUserDataJsonFile = await sql`
|
||||
SELECT starred_news from user_other_data
|
||||
where username = ${token.user}
|
||||
`;
|
||||
if (getOtherUserDataJsonFile.length === 0) {
|
||||
return {
|
||||
error: "ERR_NO_DATA",
|
||||
};
|
||||
}
|
||||
const jsonData = getOtherUserDataJsonFile[0].starred_news;
|
||||
return jsonData;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return {
|
||||
error: "INTERNAL_SERVER_ERR",
|
||||
e: e.message,
|
||||
};
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue