Skip to content

Commit b81d1b1

Browse files
committed
refactor: apply consistent code formatting and add status filter to club count query
1 parent 4a7fcbd commit b81d1b1

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

api/src/repositories/place/place.repository.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { Service } from 'typedi';
22

33
import { Db } from '../../db/db.class';
44
import { knex } from '../../db';
5-
import {Place, Store} from '../../types/models';
5+
import { Place, Store } from '../../types/models';
66

77
/** Repository for fetching/interacting with place data in the database. */
88
@Service()
99
export class PlaceRepository {
1010

11-
constructor(private db: Db) {}
12-
11+
constructor(private db: Db) { }
12+
1313
/**
1414
* Count number of clubs where type is Public or Private
1515
* and where member_id is equal to the member_id
@@ -20,11 +20,12 @@ export class PlaceRepository {
2020
const count = await knex
2121
.from('place')
2222
.count('id as count')
23-
.where({member_id: memberId})
23+
.where({ member_id: memberId })
24+
.andWhere('status', 1)
2425
.whereIn('type', ['club']);
2526
return count[0].count;
2627
}
27-
28+
2829
/**
2930
* Finds a place record with the given id.
3031
* @param id id of place to look for
@@ -42,10 +43,10 @@ export class PlaceRepository {
4243
public async findAllStores(orderBy: string): Promise<Store[]> {
4344
return this.db.knex
4445
.table('place')
45-
.where({type: 'shop', status: 1})
46-
.orderBy(orderBy,'asc');
46+
.where({ type: 'shop', status: 1 })
47+
.orderBy(orderBy, 'asc');
4748
}
48-
49+
4950
/**
5051
* Finds a place record with the given name
5152
* @param name name of place to look for
@@ -68,7 +69,7 @@ export class PlaceRepository {
6869
public async findStorageByUserID(memberId: number): Promise<any> {
6970
return this.db.place
7071
.select('place.name', 'place.id')
71-
.where({type: 'storage', member_id: memberId, status: 1})
72+
.where({ type: 'storage', member_id: memberId, status: 1 })
7273
.orderBy('place.name', 'asc');
7374
}
7475

@@ -146,16 +147,16 @@ export class PlaceRepository {
146147
limit: number,
147148
offset: number): Promise<any> {
148149
return this.db.place
149-
.where('type',compare, type)
150+
.where('type', compare, type)
150151
.where(this.like('name', search))
151152
.limit(limit)
152153
.offset(offset);
153154
}
154-
155+
155156
public searchClubs(
156-
search: string,
157-
limit: number,
158-
offset: number,
157+
search: string,
158+
limit: number,
159+
offset: number,
159160
orderBy: string,
160161
order: string,
161162
): Promise<any> {
@@ -178,7 +179,7 @@ export class PlaceRepository {
178179
.limit(limit)
179180
.offset(offset);
180181
}
181-
182+
182183
public async searchClubsTotal(search: string): Promise<any> {
183184
return this.db.place
184185
.count('id as count')
@@ -196,19 +197,19 @@ export class PlaceRepository {
196197
public async getSearchTotal(search: string, compare: string, type: string): Promise<any> {
197198
return this.db.place
198199
.count('id as count')
199-
.where('type',compare, type)
200+
.where('type', compare, type)
200201
.where(this.like('place.name', search));
201202
}
202203

203-
public async getUserPlaceTotal(id:number,type: string): Promise<any> {
204+
public async getUserPlaceTotal(id: number, type: string): Promise<any> {
204205
return await this.db.place
205206
.count('id as count')
206207
.where('type', type)
207208
.andWhere('member_id', id);
208209
}
209210

210211
private like(field: string, value: string) {
211-
return function() {
212+
return function () {
212213
this.whereRaw('?? LIKE ?', [field, `%${value}%`]);
213214
};
214215
}

0 commit comments

Comments
 (0)