Skip to content

Commit

Permalink
feat: added filter for already borrowed title on borrow screen (#155)
Browse files Browse the repository at this point in the history
* feat: add filter for already borrowed title on borrow screen
  • Loading branch information
danilolutz authored Feb 23, 2022
1 parent 416efc0 commit 6c556f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[![Build](https://github.com/librarian-org/librarian/actions/workflows/build.yml/badge.svg)](https://github.com/librarian-org/librarian/actions/workflows/build.yml)

> **NOTE**: This project is in Work-In-Progress stage, so it's not functional yet...
A free OpenSource software to handle with books. It's ideal for school libraries
and for someone who have many books.

Expand Down
32 changes: 22 additions & 10 deletions src/electron/database/repository/TitlePublisherRepository.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
import RepositoryBase from './RepositoryBase';
import { BorrowStatus } from '../../../common/BorrowStatus';

interface ListTitlePublisher {
where: unknown;
}

export default class TitlePublisherRepository extends RepositoryBase {
public async listTitle(content: ListTitlePublisher): Promise<unknown | unknown[]> {
public async listTitle(
content: ListTitlePublisher
): Promise<unknown | unknown[]> {
try {
const filter = {
relations: [
'title',
],
};
const freeTitles = await this.repository
.createQueryBuilder('titlePublisher')
.innerJoinAndSelect('titlePublisher.title', 'title')
.leftJoinAndSelect('titlePublisher.borrow', 'borrow')
.where('borrow.isReservation IS NULL')
.orWhere((qb) => {
const subQuery = qb
.subQuery()
.select('borrow.Id')
.from('borrow', 'borrow')
.where('borrow.status IN (:...ids)', {
ids: [BorrowStatus.Returned, BorrowStatus.LateReturned],
})
.getQuery();

// if (content.where) {
// filter = { ...filter, ...{ where: content } };
// }
return `"titlePublisher"."id" IN ${subQuery}`;
})
.getMany();

return await this.repository.find(filter);
return freeTitles;
} catch (err) {
console.log(err);
throw err;
Expand Down

0 comments on commit 6c556f8

Please sign in to comment.