26 lines
667 B
TypeScript
26 lines
667 B
TypeScript
|
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()
|
||
|
});
|
||
|
}
|
||
|
}
|