task_receipts/server/src/db/repositories/step-repository.ts

26 lines
667 B
TypeScript
Raw Normal View History

2025-06-14 23:04:05 +00:00
import { Knex } from 'knex';
import { BaseRepository } from './base-repository';
import { Step } from '@shared/index';
export class StepRepository extends BaseRepository<Step> {
constructor(db: Knex) {
super(db, 'steps');
}
async findByTaskId(taskId: number): Promise<Step[]> {
return await this.db(this.tableName)
.where('task_id', taskId)
.orderBy('order')
.select('*');
}
async incrementPrintCount(id: number): Promise<boolean> {
const step = await this.findById(id);
if (!step) return false;
return await this.update(id, {
print_count: step.print_count + 1,
last_printed_at: new Date()
});
}
}