You've already forked obsidian-visualiser
Add insertion and deletion of tables for db sync, and user view
This commit is contained in:
@@ -62,13 +62,13 @@ export default defineEventHandler(async (e): Promise<Return> => {
|
||||
{
|
||||
const hash = await Bun.password.hash(body.data.password);
|
||||
const registration = db.query(`INSERT INTO users(username, email, hash, state) VALUES(?1, ?2, ?3, 0)`);
|
||||
registration.get(body.data.username, body.data.email, hash) as any;
|
||||
registration.run(body.data.username, body.data.email, hash);
|
||||
|
||||
const userIdQuery = db.query(`SELECT id FROM users WHERE username = ?1`);
|
||||
const id = (userIdQuery.get(body.data.username) as any).id;
|
||||
|
||||
const registeringData = db.query(`INSERT INTO users_data(user_id) VALUES(?1)`);
|
||||
registeringData.get(id);
|
||||
const registeringData = db.query(`INSERT INTO users_data(user_id, signin_timestamp) VALUES(?1, ?2)`);
|
||||
registeringData.run(id, Date.now());
|
||||
|
||||
logSession(e, await setUserSession(e, { user: { id: id, username: body.data.username, email: body.data.email, state: 0 } }) as UserSessionRequired);
|
||||
|
||||
|
||||
@@ -12,5 +12,5 @@ export default defineEventHandler((e) => {
|
||||
|
||||
const db = useDatabase();
|
||||
|
||||
return db.query(`SELECT id, usernamme, email, state FROM users WHERE id = ?1`).get(id) as User;
|
||||
return db.query(`SELECT id, username, email, state, d.* FROM users u LEFT JOIN users_data d ON u.id = d.user_id WHERE u.id = ?1`).get(id) as User;
|
||||
});
|
||||
16
server/api/users/[id]/comments.get.ts
Normal file
16
server/api/users/[id]/comments.get.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import useDatabase from "~/composables/useDatabase";
|
||||
import type { Comment } from "~/types/auth";
|
||||
|
||||
export default defineEventHandler((e) => {
|
||||
const id = getRouterParam(e, 'id');
|
||||
|
||||
if(!id)
|
||||
{
|
||||
setResponseStatus(e, 400);
|
||||
return;
|
||||
}
|
||||
|
||||
const db = useDatabase();
|
||||
|
||||
return db.query(`SELECT * FROM explorer_comments WHERE user_id = ?1`).all(id) as Comment[];
|
||||
});
|
||||
16
server/api/users/[id]/projects.get.ts
Normal file
16
server/api/users/[id]/projects.get.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import useDatabase from "~/composables/useDatabase";
|
||||
import type { Project } from "~/types/api";
|
||||
|
||||
export default defineEventHandler((e) => {
|
||||
const id = getRouterParam(e, 'id');
|
||||
|
||||
if(!id)
|
||||
{
|
||||
setResponseStatus(e, 400);
|
||||
return;
|
||||
}
|
||||
|
||||
const db = useDatabase();
|
||||
|
||||
return db.query(`SELECT * FROM explorer_projects WHERE owner = ?1`).all(id) as Project[];
|
||||
});
|
||||
Reference in New Issue
Block a user