refactor: little light renaming

This commit is contained in:
Andy Burke 2025-06-24 16:17:00 -07:00
parent eef7b29223
commit 6f69695758
7 changed files with 31 additions and 31 deletions

View file

@ -1,7 +1,7 @@
import { PASSWORD_ENTRY, PASSWORD_ENTRY_STORE } from '../../../../models/password_entry.ts';
import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../../models/password_entry.ts';
import { SESSIONS } from '../../../../models/session.ts';
import { USER, USER_STORE } from '../../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../../models/user_permissions.ts';
import { USER, USERS } from '../../../../models/user.ts';
import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../../models/user_permissions.ts';
import parse_body from '../../../../utils/bodyparser.ts';
export const PERMISSIONS: Record<string, (req: Request, meta: Record<string, any>) => Promise<boolean>> = {};
@ -16,7 +16,7 @@ PERMISSIONS.GET = (_req: Request, meta: Record<string, any>): Promise<boolean> =
};
export async function GET(_req: Request, meta: Record<string, any>): Promise<Response> {
const user_id: string = meta.params?.id?.toLowerCase().trim() ?? '';
const user: USER | null = user_id.length === 49 ? await USER_STORE.get(user_id) : null; // lurid is 49 chars as we use them, eg: "also-play-flow-want-form-wide-thus-work-burn-same"
const user: USER | null = user_id.length === 49 ? await USERS.get(user_id) : null; // lurid is 49 chars as we use them, eg: "also-play-flow-want-form-wide-thus-work-burn-same"
if (!user) {
return Response.json({
@ -60,7 +60,7 @@ PERMISSIONS.PUT = (_req: Request, meta: Record<string, any>): Promise<boolean> =
export async function PUT(req: Request, meta: { params: Record<string, any> }): Promise<Response> {
const now = new Date().toISOString();
const id: string = meta.params.id ?? '';
const existing = await USER_STORE.get(id);
const existing = await USERS.get(id);
if (!existing) {
return Response.json({
@ -84,7 +84,7 @@ export async function PUT(req: Request, meta: { params: Record<string, any> }):
}
};
await USER_STORE.update(updated);
await USERS.update(updated);
return Response.json(updated, {
status: 200
});
@ -111,7 +111,7 @@ PERMISSIONS.DELETE = (_req: Request, meta: Record<string, any>): Promise<boolean
export async function DELETE(_req: Request, meta: { params: Record<string, any> }): Promise<Response> {
const user_id: string = meta.params.id ?? '';
const user: USER | null = await USER_STORE.get(user_id);
const user: USER | null = await USERS.get(user_id);
if (!user) {
return Response.json({
error: {
@ -123,13 +123,13 @@ export async function DELETE(_req: Request, meta: { params: Record<string, any>
});
}
const password_entry: PASSWORD_ENTRY | null = await PASSWORD_ENTRY_STORE.get(user_id);
const password_entry: PASSWORD_ENTRY | null = await PASSWORD_ENTRIES.get(user_id);
if (password_entry) {
await PASSWORD_ENTRY_STORE.delete(password_entry);
await PASSWORD_ENTRIES.delete(password_entry);
}
const user_permissions: USER_PERMISSIONS | null = await USER_PERMISSIONS_STORE.get(user_id);
const user_permissions: USER_PERMISSIONS | null = await PERMISSIONS_STORE.get(user_id);
if (user_permissions) {
await USER_PERMISSIONS_STORE.delete(user_permissions);
await PERMISSIONS_STORE.delete(user_permissions);
}
const sessions = await SESSIONS.find({
@ -139,7 +139,7 @@ export async function DELETE(_req: Request, meta: { params: Record<string, any>
await SESSIONS.delete(session);
}
await USER_STORE.delete(user);
await USERS.delete(user);
return Response.json({
deleted: true

View file

@ -1,6 +1,6 @@
import { PASSWORD_ENTRY, PASSWORD_ENTRY_STORE } from '../../../models/password_entry.ts';
import { USER, USER_STORE } from '../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../models/user_permissions.ts';
import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../models/password_entry.ts';
import { USER, USERS } from '../../../models/user.ts';
import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../models/user_permissions.ts';
import { generateSecret } from 'jsr:@stdext/crypto/utils';
import { hash } from 'jsr:@stdext/crypto/hash';
import lurid from 'jsr:@andyburke/lurid';
@ -45,7 +45,7 @@ export async function GET(_req: Request, meta: Record<string, any>): Promise<Res
}
const limit = Math.min(parseInt(query.get('limit') ?? '10'), 100);
const users = await USER_STORE.find({
const users = await USERS.find({
id: partial_id
}, {
limit
@ -65,7 +65,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
const username: string = body.username?.trim() ?? '';
const normalized_username = username.toLowerCase();
const existing_user_with_username = (await USER_STORE.find({
const existing_user_with_username = (await USERS.find({
normalized_username
})).shift();
if (existing_user_with_username) {
@ -104,7 +104,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
}
};
await USER_STORE.create(user);
await USERS.create(user);
const salt = generateSecret();
const hashed_password_value = hash('bcrypt', `${password_hash}${salt}`);
@ -119,7 +119,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
}
};
await PASSWORD_ENTRY_STORE.create(password_entry);
await PASSWORD_ENTRIES.create(password_entry);
const user_permissions: USER_PERMISSIONS = {
user_id: user.id,
@ -130,7 +130,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
}
};
await USER_PERMISSIONS_STORE.create(user_permissions);
await PERMISSIONS_STORE.create(user_permissions);
const session_result: SESSION_RESULT = await get_session({
user,