Add task service.

Database interactions will be handled by service classes. Service
classes will be called by page load functions as well as by API
endpoints. This will allow one source of truth for authorization and
data validation.
This commit is contained in:
themodrnhakr 2025-09-27 11:01:38 -05:00
parent 2c9b855d2a
commit a0d12d4661

View File

@ -0,0 +1,25 @@
import { type DB, db } from "$lib/server/db/db";
import logger from "../logger";
class TasksService {
private db: DB;
private caller: "internal" | "api";
constructor(caller: "internal" | "api", dbClient: DB = db) {
this.db = dbClient;
this.caller = caller;
}
public async getAll() {
logger.info("Fetching all task records...");
try {
const result = await this.db.query.tasks.findMany();
logger.debug(`Found ${result.length} records.`);
return result;
} catch (e) {
logger.error({ msg: "Error querying the database.", error: e });
return false;
}
}
}
export default TasksService;