Following is the record in table -
I need to select records based on the batches (last column). I have my end point like -
http://localhost:3000/batch/Batch 3
This is my controller and works fine and redirect the call to service -
@Get('/batch/:batchName')
getByBatch(@Param('batchName') batch): Promise<Assignment[]> {
return this.assignmentService.getByBatch(batch);
}
This is my service -
async getByBatch(batch: string): Promise<Batch[]> {
return await getRepository(Assignment)
.createQueryBuilder('a')
.where('a.batches CONTAINS :batch', { batch: batch })
.getMany();
}
I am not sure as how the query would be formed in this case. I am using typeorm and postgres.
For simple queries, I have directly used repository like -
return this.assgRepository.findOne({ id: id });
Following is the entity -
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column()
description: string;
@Column({ array: true })
batches: string;
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
createdAt: string;
I need to pass a batch and fetch records which ever contain that batch.
P.S. If you could also point me as how can I update the batches would be great.
