Skip to content

Commit 3dfc52b

Browse files
authored
Merge pull request #406 from smile0711:access-updates-and-issue-369
Access updates and issue 369
2 parents 1f3823b + b81d1b1 commit 3dfc52b

5 files changed

Lines changed: 178 additions & 152 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
}

api/src/services/colony/colony.service.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../../repositories';
99
import { Place } from '../../types/models';
1010
import * as console from 'console';
11-
import {includes} from 'lodash';
11+
import { includes } from 'lodash';
1212

1313
/** Service for dealing with colony */
1414
@Service()
@@ -18,16 +18,16 @@ export class ColonyService {
1818
private roleAssignmentRepository: RoleAssignmentRepository,
1919
private roleRepository: RoleRepository,
2020
private memberRepository: MemberRepository,
21-
) {}
22-
21+
) { }
22+
2323
public async find(colonyId: number): Promise<Place> {
2424
return await this.colonyRepository.find(colonyId);
2525
}
2626

2727
public async getHoods(colonyId: number): Promise<any> {
2828
return await this.colonyRepository.getHoods(colonyId);
2929
}
30-
30+
3131
public async getAccessInfoByUsername(colonyId: number): Promise<object> {
3232
const deputyCode = await this.roleRepository.roleMap.ColonyDeputy;
3333
const ownerCode = await this.roleRepository.roleMap.ColonyLeader;
@@ -50,8 +50,8 @@ export class ColonyService {
5050
const ownerCode = await this.roleRepository.roleMap.ColonyLeader;
5151
let oldOwner = null;
5252
let newOwner = 0;
53-
const oldDeputies = [0,0,0,0,0,0,0,0];
54-
const newDeputies = [0,0,0,0,0,0,0,0];
53+
const oldDeputies = [0, 0, 0, 0, 0, 0, 0, 0];
54+
const newDeputies = [0, 0, 0, 0, 0, 0, 0, 0];
5555
const data = await this
5656
.roleAssignmentRepository
5757
.getAccessInfoByID(colonyId, ownerCode, deputyCode);
@@ -72,8 +72,8 @@ export class ColonyService {
7272
const response: any = await this.memberRepository.getPrimaryRoleName(oldOwner);
7373
if (response.length !== 0) {
7474
const primaryRoleId = response[0].primary_role_id;
75-
if (ownerCode === primaryRoleId){
76-
await this.memberRepository.update(oldOwner, {primary_role_id: null});
75+
if (ownerCode === primaryRoleId) {
76+
await this.memberRepository.update(oldOwner, { primary_role_id: null });
7777
}
7878
}
7979
}
@@ -84,8 +84,8 @@ export class ColonyService {
8484
const response: any = await this.memberRepository.getPrimaryRoleName(oldOwner);
8585
if (response.length !== 0) {
8686
const primaryRoleId = response[0].primary_role_id;
87-
if (ownerCode === primaryRoleId){
88-
await this.memberRepository.update(oldOwner, {primary_role_id: null});
87+
if (ownerCode === primaryRoleId) {
88+
await this.memberRepository.update(oldOwner, { primary_role_id: null });
8989
}
9090
}
9191
}
@@ -110,7 +110,7 @@ export class ColonyService {
110110
if (response.length !== 0) {
111111
const primaryRoleId = response[0].primary_role_id;
112112
if (primaryRoleId && deputyCode === primaryRoleId) {
113-
this.memberRepository.update(oldDeputies, {primary_role_id: null});
113+
this.memberRepository.update(oldDeputies, { primary_role_id: null });
114114
}
115115
}
116116
});
@@ -123,7 +123,7 @@ export class ColonyService {
123123
if (response.length !== 0) {
124124
const primaryRoleId = response[0].primary_role_id;
125125
if (deputyCode === primaryRoleId) {
126-
this.memberRepository.update(oldDeputies, {primary_role_id: null});
126+
this.memberRepository.update(oldDeputies, { primary_role_id: null });
127127
}
128128
}
129129
});
@@ -146,8 +146,6 @@ export class ColonyService {
146146
return (
147147
[
148148
this.roleRepository.roleMap.Admin,
149-
this.roleRepository.roleMap.CityMayor,
150-
this.roleRepository.roleMap.DeputyMayor,
151149
this.roleRepository.roleMap.ColonyRepresentative,
152150
].includes(assignment.role_id) ||
153151
([

api/src/services/inbox/inbox.service.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
import { Service } from 'typedi';
22

3-
import { InboxRepository, ColonyRepository } from '../../repositories';
3+
import { InboxRepository } from '../../repositories';
44
import sanitizeHtml from 'sanitize-html';
5-
import { stringify } from 'ts-jest';
6-
import {forEach} from 'lodash';
75

86
/** Service for dealing with messages on message boards */
97
@Service()
108
export class InboxService {
11-
public static readonly MAX_QUERY_LIMIT = 1000;
12-
public static readonly VALID_ORDERS = ['id', 'date'];
13-
public static readonly VALID_ORDER_DIRECTIONS = ['asc', 'desc'];
149

15-
constructor(private inboxRepository: InboxRepository) {}
10+
constructor(private inboxRepository: InboxRepository) { }
1611

1712
public async changeInboxIntro(placeId, Intro): Promise<any> {
1813
console.log(`Service${placeId}`);
1914
return await this.inboxRepository.changeInboxIntro(placeId, Intro);
2015
}
2116

22-
public async deleteInboxMessages(
23-
messageIds: number[],
24-
placeId: number,
25-
): Promise<any> {
26-
return this.inboxRepository.deleteInboxMessages(messageIds, placeId);
27-
}
17+
public async deleteInboxMessages(
18+
messageIds: number[],
19+
placeId: number,
20+
): Promise<any> {
21+
return this.inboxRepository.deleteInboxMessages(messageIds, placeId);
22+
}
2823

2924
public async getAdminInfo(placeId, memberId): Promise<any> {
3025
return await this.inboxRepository.getAdminInfo(placeId, memberId);
@@ -45,7 +40,7 @@ export class InboxService {
4540
): Promise<any> {
4641
return await this.inboxRepository.postInboxMessage(memberId, placeId, subject, message);
4742
}
48-
43+
4944
public async postInboxAllMessage(
5045
memberId: number,
5146
locations: number[],
@@ -80,8 +75,6 @@ export class InboxService {
8075
);
8176
}
8277

83-
84-
8578
public async sanitize(uncleanInfo: string): Promise<any> {
8679
const cleanInfo = sanitizeHtml(uncleanInfo, {
8780
allowedTags: [
@@ -167,8 +160,8 @@ export class InboxService {
167160
a: ['href', 'name', 'target'],
168161
img: ['src', 'srcset', 'alt', 'title', 'width', 'height', 'usemap'],
169162
font: ['color', 'size'],
170-
map: [ 'name' ],
171-
area: [ 'alt', 'title', 'href', 'coords', 'shape', 'target', 'class' ],
163+
map: ['name'],
164+
area: ['alt', 'title', 'href', 'coords', 'shape', 'target', 'class'],
172165
marquee: ['width', 'height', 'direction'],
173166
},
174167
});

0 commit comments

Comments
 (0)