Handle cashback commission imports, include commissions in analytics with separate investment metrics, and expose commission/version details in the UI. Made-with: Cursor
35 lines
900 B
TypeScript
35 lines
900 B
TypeScript
import { v4 as uuidv4 } from 'uuid';
|
|
import { pool } from '../db/pool';
|
|
import { config } from '../config';
|
|
import type { LoginRequest, MeResponse } from '@family-budget/shared';
|
|
import backendPackage from '../../package.json';
|
|
|
|
export async function login(
|
|
body: LoginRequest,
|
|
): Promise<{ sessionId: string } | null> {
|
|
if (body.login !== config.appUserLogin || body.password !== config.appUserPassword) {
|
|
return null;
|
|
}
|
|
|
|
const sid = uuidv4();
|
|
await pool.query(
|
|
'INSERT INTO sessions (id) VALUES ($1)',
|
|
[sid],
|
|
);
|
|
return { sessionId: sid };
|
|
}
|
|
|
|
export async function logout(sessionId: string): Promise<void> {
|
|
await pool.query(
|
|
'UPDATE sessions SET is_active = FALSE WHERE id = $1',
|
|
[sessionId],
|
|
);
|
|
}
|
|
|
|
export async function me(sessionId: string): Promise<MeResponse> {
|
|
return {
|
|
login: config.appUserLogin,
|
|
backendVersion: backendPackage.version,
|
|
};
|
|
}
|