@@ -20,13 +20,13 @@ export class PlaceService {
2020 private roleRepository : RoleRepository ,
2121 private roleAssignmentRepository : RoleAssignmentRepository ,
2222 private virtualPetRepository : VirtualPetRepository ,
23- ) { }
23+ ) { }
2424
2525 public async canAdmin ( slug : string , placeId : number , memberId : number ) :
26- Promise < boolean > {
26+ Promise < boolean > {
2727 const placeRoleId = await this . findRoleIdsBySlug ( slug ) ;
2828 const roleAssignments = await this . roleAssignmentRepository . getByMemberId ( memberId ) ;
29-
29+
3030 //check club admin ability
3131 if ( slug === 'personalclub' ) {
3232 if (
@@ -35,20 +35,20 @@ export class PlaceService {
3535 [
3636 this . roleRepository . roleMap . Admin ,
3737 ] . includes ( assignment . role_id ) ||
38- ( [
39- this . roleRepository . roleMap . ClubOwner ,
40- this . roleRepository . roleMap . ClubAssistant ,
41- placeRoleId . deputy ,
42- ] . includes ( assignment . role_id ) &&
43- assignment . place_id === placeId )
38+ ( [
39+ this . roleRepository . roleMap . ClubOwner ,
40+ this . roleRepository . roleMap . ClubAssistant ,
41+ placeRoleId . deputy ,
42+ ] . includes ( assignment . role_id ) &&
43+ assignment . place_id === placeId )
4444 ) ;
4545 } )
4646 ) {
4747 return true ;
4848 }
4949 }
5050 if ( slug === 'cityhall' ) {
51- if (
51+ if (
5252 roleAssignments . find ( assignment => {
5353 return (
5454 [
@@ -59,7 +59,20 @@ export class PlaceService {
5959 return true ;
6060 }
6161 }
62-
62+ if ( slug === 'newcomers' ) {
63+ if (
64+ roleAssignments . find ( assignment => {
65+ return (
66+ [
67+ this . roleRepository . roleMap . SeniorCityGuide ,
68+ this . roleRepository . roleMap . CityGuide ,
69+ ] . includes ( assignment . role_id )
70+ ) ;
71+ } ) ) {
72+ return true ;
73+ }
74+ }
75+
6376 //check if admin even if there is no assigned roles for the place
6477 if ( ! placeRoleId ) {
6578 if (
@@ -84,11 +97,11 @@ export class PlaceService {
8497 this . roleRepository . roleMap . Admin ,
8598 this . roleRepository . roleMap . PlacesChief ,
8699 ] . includes ( assignment . role_id ) ||
87- ( [
88- placeRoleId . owner ,
89- placeRoleId . deputy ,
90- ] . includes ( assignment . role_id ) &&
91- assignment . place_id === placeId )
100+ ( [
101+ placeRoleId . owner ,
102+ placeRoleId . deputy ,
103+ ] . includes ( assignment . role_id ) &&
104+ assignment . place_id === placeId )
92105 ) ;
93106 } )
94107 ) {
@@ -102,7 +115,7 @@ export class PlaceService {
102115 const placeRoleId = await this . findRoleIdsBySlug ( slug ) ;
103116 const roleAssignments = await this . roleAssignmentRepository . getByMemberId ( memberId ) ;
104117 //if no roles assignable, access rights is closed to all
105- if ( ! placeRoleId ) return false ;
118+ if ( ! placeRoleId ) return false ;
106119
107120 if (
108121 roleAssignments . find ( assignment => {
@@ -111,8 +124,8 @@ export class PlaceService {
111124 this . roleRepository . roleMap . Admin ,
112125 this . roleRepository . roleMap . PlacesChief ,
113126 ] . includes ( assignment . role_id ) ||
114- ( [ placeRoleId . owner ] . includes ( assignment . role_id ) &&
115- assignment . place_id === placeId )
127+ ( [ placeRoleId . owner ] . includes ( assignment . role_id ) &&
128+ assignment . place_id === placeId )
116129 ) ;
117130 } )
118131 ) {
@@ -132,26 +145,26 @@ export class PlaceService {
132145 public async getPlaceObjects ( placeId : number ) : Promise < ObjectInstance [ ] > {
133146 return await this . objectInstanceRepository . findByPlaceId ( placeId ) ;
134147 }
135-
148+
136149 public async getAccessInfoByUsername ( slug : string , placeId : number ) : Promise < object > {
137150 const placeRoleId = await this . findRoleIdsBySlug ( slug ) ;
138151 return await this
139152 . roleAssignmentRepository
140153 . getAccessInfoByUsername ( placeId , placeRoleId . owner , placeRoleId . deputy ) ;
141154 }
142-
155+
143156 public async getSecurityInfo ( ) : Promise < object > {
144157 const SecurityInfo = { } ;
145- const securityRoles = [
146- { mapName : 'SecurityChief' , roleName : 'Security Chief' } ,
147- { mapName : 'SecurityCaptain' , roleName : 'Security Captain' } ,
148- { mapName : 'SecurityLieutenant' , roleName : 'Security Lieutenant' } ,
149- { mapName : 'SecuritySergeant' , roleName : 'Security Sergeant' } ,
150- { mapName : 'SecurityOfficer' , roleName : 'Security Officer' } ,
151- { mapName : 'JailGuard' , roleName : 'Jail Guard' } ,
158+ const securityRoles = [
159+ { mapName : 'SecurityChief' , roleName : 'Security Chief' } ,
160+ { mapName : 'SecurityCaptain' , roleName : 'Security Captain' } ,
161+ { mapName : 'SecurityLieutenant' , roleName : 'Security Lieutenant' } ,
162+ { mapName : 'SecuritySergeant' , roleName : 'Security Sergeant' } ,
163+ { mapName : 'SecurityOfficer' , roleName : 'Security Officer' } ,
164+ { mapName : 'JailGuard' , roleName : 'Jail Guard' } ,
152165 ] ;
153166 try {
154- await Promise . all ( securityRoles . map ( async ( role ) => {
167+ await Promise . all ( securityRoles . map ( async ( role ) => {
155168 const roleCode = await this . roleRepository . roleMap [ role . mapName ] ;
156169 await this . roleAssignmentRepository . getUsernamesByRoleId ( roleCode ) . then ( response => {
157170 const users = [ ] ;
@@ -168,9 +181,9 @@ export class PlaceService {
168181 }
169182
170183 public async addStorage ( name : string , memberId : number ) : Promise < any > {
171- await this . placeRepository . create ( { name : name , type : 'storage' , member_id : memberId } ) ;
184+ await this . placeRepository . create ( { name : name , type : 'storage' , member_id : memberId } ) ;
172185 }
173-
186+
174187 public async deleteStorage ( id : number ) : Promise < any > {
175188 await this . placeRepository . deleteStorageArea ( id ) ;
176189 }
@@ -189,8 +202,8 @@ export class PlaceService {
189202 const ownerCode = placeRoleId . owner ;
190203 let oldOwner = null ;
191204 let newOwner = 0 ;
192- const oldDeputies = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
193- const newDeputies = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
205+ const oldDeputies = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
206+ const newDeputies = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
194207 const data = await this
195208 . roleAssignmentRepository
196209 . getAccessInfoByID ( placeId , ownerCode , deputyCode ) ;
@@ -211,8 +224,8 @@ export class PlaceService {
211224 const response : any = await this . memberRepository . getPrimaryRoleName ( oldOwner ) ;
212225 if ( response . length !== 0 ) {
213226 const primaryRoleId = response [ 0 ] . primary_role_id ;
214- if ( ownerCode === primaryRoleId ) {
215- await this . memberRepository . update ( oldOwner , { primary_role_id : null } ) ;
227+ if ( ownerCode === primaryRoleId ) {
228+ await this . memberRepository . update ( oldOwner , { primary_role_id : null } ) ;
216229 }
217230 }
218231 }
@@ -223,8 +236,8 @@ export class PlaceService {
223236 const response : any = await this . memberRepository . getPrimaryRoleName ( oldOwner ) ;
224237 if ( response . length !== 0 ) {
225238 const primaryRoleId = response [ 0 ] . primary_role_id ;
226- if ( ownerCode === primaryRoleId ) {
227- await this . memberRepository . update ( oldOwner , { primary_role_id : null } ) ;
239+ if ( ownerCode === primaryRoleId ) {
240+ await this . memberRepository . update ( oldOwner , { primary_role_id : null } ) ;
228241 }
229242 }
230243 }
@@ -249,7 +262,7 @@ export class PlaceService {
249262 if ( response . length !== 0 ) {
250263 const primaryRoleId = response [ 0 ] . primary_role_id ;
251264 if ( primaryRoleId && deputyCode === primaryRoleId ) {
252- this . memberRepository . update ( oldDeputies , { primary_role_id : null } ) ;
265+ this . memberRepository . update ( oldDeputies , { primary_role_id : null } ) ;
253266 }
254267 }
255268 } ) ;
@@ -262,7 +275,7 @@ export class PlaceService {
262275 if ( response . length !== 0 ) {
263276 const primaryRoleId = response [ 0 ] . primary_role_id ;
264277 if ( deputyCode === primaryRoleId ) {
265- this . memberRepository . update ( oldDeputies , { primary_role_id : null } ) ;
278+ this . memberRepository . update ( oldDeputies , { primary_role_id : null } ) ;
266279 }
267280 }
268281 } ) ;
@@ -280,7 +293,7 @@ export class PlaceService {
280293 return await this . placeRepository . updatePlaces ( placeinfo ) ;
281294 }
282295
283- private async findRoleIdsBySlug ( slug : string ) : Promise < { owner : number , deputy : number } > {
296+ private async findRoleIdsBySlug ( slug : string ) : Promise < { owner : number , deputy : number } > {
284297 const roleId = {
285298 bank : {
286299 owner : this . roleRepository . roleMap . BankManager ,
@@ -371,7 +384,7 @@ export class PlaceService {
371384 return newDeputies ;
372385 }
373386
374- public async findUserPlaces ( id : number , type : string ) : Promise < any > {
387+ public async findUserPlaces ( id : number , type : string ) : Promise < any > {
375388 let returnPlaces = [ ] ;
376389 const places = await this . placeRepository . findUserPlaces ( id , type ) ;
377390 returnPlaces = places ;
@@ -383,17 +396,17 @@ export class PlaceService {
383396 }
384397
385398 public async searchAllPlaces (
386- search : string ,
387- compare : string ,
388- type : string ,
389- limit : number ,
399+ search : string ,
400+ compare : string ,
401+ type : string ,
402+ limit : number ,
390403 offset : number ) : Promise < any > {
391404 const ownerRequired = [ 'home' , 'club' , 'storage' ] ;
392405 let returnPlaces = [ ] ;
393406 const places = await this . placeRepository . searchAllPlaces (
394407 search , compare , type , limit , offset ) ;
395- if ( ownerRequired . includes ( type ) ) {
396- for ( const place of places ) {
408+ if ( ownerRequired . includes ( type ) ) {
409+ for ( const place of places ) {
397410 const user = await this . memberRepository . findById ( place . member_id ) ;
398411 place . username = user . username ;
399412 returnPlaces . push ( place ) ;
@@ -408,49 +421,69 @@ export class PlaceService {
408421 } ;
409422 }
410423
411- public async addVirtualPet ( placeId : number ) : Promise < any > {
424+ public async addVirtualPet ( placeId : number ) : Promise < any > {
412425 const name = 'VirtualPet' ;
413426 const avatar = '/assets/pets/dog/dog.wrl' ;
414427 const behaviours = [
415- { id : 0 , match : 'exact' , directly : false , input : '' ,
416- whisper : false , beam : false , output : '' , } ,
417- { id : 1 , match : 'exact' , directly : false , input : '' ,
418- whisper : false , beam : false , output : '' , } ,
419- { id : 2 , match : 'exact' , directly : false , input : '' ,
420- whisper : false , beam : false , output : '' , } ,
421- { id : 3 , match : 'exact' , directly : false , input : '' ,
422- whisper : false , beam : false , output : '' , } ,
423- { id : 4 , match : 'exact' , directly : false , input : '' ,
424- whisper : false , beam : false , output : '' , } ,
425- { id : 5 , match : 'exact' , directly : false , input : '' ,
426- whisper : false , beam : false , output : '' , } ,
427- { id : 6 , match : 'exact' , directly : false , input : '' ,
428- whisper : false , beam : false , output : '' , } ,
429- { id : 7 , match : 'exact' , directly : false , input : '' ,
430- whisper : false , beam : false , output : '' , } ,
431- { id : 8 , match : 'exact' , directly : false , input : '' ,
432- whisper : false , beam : false , output : '' , } ,
433- { id : 9 , match : 'exact' , directly : false , input : '' ,
434- whisper : false , beam : false , output : '' , } ,
428+ {
429+ id : 0 , match : 'exact' , directly : false , input : '' ,
430+ whisper : false , beam : false , output : '' ,
431+ } ,
432+ {
433+ id : 1 , match : 'exact' , directly : false , input : '' ,
434+ whisper : false , beam : false , output : '' ,
435+ } ,
436+ {
437+ id : 2 , match : 'exact' , directly : false , input : '' ,
438+ whisper : false , beam : false , output : '' ,
439+ } ,
440+ {
441+ id : 3 , match : 'exact' , directly : false , input : '' ,
442+ whisper : false , beam : false , output : '' ,
443+ } ,
444+ {
445+ id : 4 , match : 'exact' , directly : false , input : '' ,
446+ whisper : false , beam : false , output : '' ,
447+ } ,
448+ {
449+ id : 5 , match : 'exact' , directly : false , input : '' ,
450+ whisper : false , beam : false , output : '' ,
451+ } ,
452+ {
453+ id : 6 , match : 'exact' , directly : false , input : '' ,
454+ whisper : false , beam : false , output : '' ,
455+ } ,
456+ {
457+ id : 7 , match : 'exact' , directly : false , input : '' ,
458+ whisper : false , beam : false , output : '' ,
459+ } ,
460+ {
461+ id : 8 , match : 'exact' , directly : false , input : '' ,
462+ whisper : false , beam : false , output : '' ,
463+ } ,
464+ {
465+ id : 9 , match : 'exact' , directly : false , input : '' ,
466+ whisper : false , beam : false , output : '' ,
467+ } ,
435468 ] ;
436469 return await this . virtualPetRepository
437470 . addVirtualPet ( placeId , name , avatar , JSON . stringify ( behaviours ) ) ;
438- }
471+ }
439472
440473 public async getVirtualPet ( placeId : number ) : Promise < any > {
441474 const virtualPet = await this . virtualPetRepository . getVirtualPet ( placeId ) ;
442475 return virtualPet ;
443476 }
444477
445478 public async updateVirtualPet (
446- placeId : number ,
447- name : string ,
448- avatar : string ,
449- active : boolean ,
479+ placeId : number ,
480+ name : string ,
481+ avatar : string ,
482+ active : boolean ,
450483 voice : number ,
451484 behaviours : string ) : Promise < any > {
452485 await this . virtualPetRepository . updateVirtualPet (
453- placeId ,
486+ placeId ,
454487 name ,
455488 avatar ,
456489 active ,
0 commit comments