forked from aesirxio/bi-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aesirxio#250 from vietredweb/member
Roles, Member Role
- Loading branch information
Showing
14 changed files
with
836 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* @copyright Copyright (C) 2022 AesirX. All rights reserved. | ||
* @license GNU General Public License version 3, see LICENSE. | ||
*/ | ||
|
||
import BaseItemModel from '../../Abstract/BaseItemModel'; | ||
import BaseModel from '../../Abstract/BaseModel'; | ||
import { MEMBER_ROLE_FIELD } from '../../Constant/OrganizationContent'; | ||
|
||
class MemberRoleModel extends BaseModel { | ||
constructor(entities: any) { | ||
super(entities); | ||
if (entities) { | ||
this.items = entities._embedded?.item.map((element: any) => { | ||
return new MemberRoleItemModel(element); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
class MemberRoleItemModel extends BaseItemModel { | ||
id: number = 0; | ||
member_id = null; | ||
member_name = null; | ||
role_id = null; | ||
role_name = null; | ||
organisation_id = null; | ||
name = null; | ||
state = null; | ||
published = null; | ||
created_user_name = null; | ||
modified_user_name = null; | ||
created_time = null; | ||
modified_time = null; | ||
constructor(entity: any) { | ||
super(entity); | ||
if (entity) { | ||
this.id = entity[MEMBER_ROLE_FIELD.ID] ?? 0; | ||
this.member_id = entity[MEMBER_ROLE_FIELD.MEMBER_ID] ?? 0; | ||
this.member_name = entity[MEMBER_ROLE_FIELD.MEMBER_NAME] ?? ''; | ||
this.role_id = entity[MEMBER_ROLE_FIELD.ROLE_ID] ?? 0; | ||
this.role_name = entity[MEMBER_ROLE_FIELD.ROLE_NAME] ?? ''; | ||
this.name = entity[MEMBER_ROLE_FIELD.NAME] ?? ''; | ||
this.state = entity[MEMBER_ROLE_FIELD.STATE] ?? ''; | ||
this.published = entity[MEMBER_ROLE_FIELD.PUBLISHED] ?? 0; | ||
this.organisation_id = entity[MEMBER_ROLE_FIELD.ORGANISATION_ID] ?? 0; | ||
this.created_user_name = entity[MEMBER_ROLE_FIELD.CREATED_USER_NAME] ?? ''; | ||
this.modified_user_name = entity[MEMBER_ROLE_FIELD.MODIFIED_USER_NAME] ?? ''; | ||
this.created_time = entity[MEMBER_ROLE_FIELD.CREATED_TIME] ?? ''; | ||
this.modified_time = entity[MEMBER_ROLE_FIELD.MODIFIED_TIME] ?? ''; | ||
} | ||
} | ||
|
||
toJSON = () => { | ||
return { | ||
...this.baseToJSON(), | ||
[MEMBER_ROLE_FIELD.ID]: this.id, | ||
[MEMBER_ROLE_FIELD.MEMBER_ID]: this.member_id, | ||
[MEMBER_ROLE_FIELD.MEMBER_NAME]: this.member_name, | ||
[MEMBER_ROLE_FIELD.ROLE_ID]: this.role_id, | ||
[MEMBER_ROLE_FIELD.ROLE_NAME]: this.role_name, | ||
[MEMBER_ROLE_FIELD.NAME]: this.name, | ||
[MEMBER_ROLE_FIELD.STATE]: this.state, | ||
[MEMBER_ROLE_FIELD.PUBLISHED]: this.published, | ||
[MEMBER_ROLE_FIELD.ORGANISATION_ID]: this.organisation_id, | ||
[MEMBER_ROLE_FIELD.CREATED_USER_NAME]: this.created_user_name, | ||
[MEMBER_ROLE_FIELD.MODIFIED_USER_NAME]: this.modified_user_name, | ||
[MEMBER_ROLE_FIELD.CREATED_TIME]: this.created_time, | ||
[MEMBER_ROLE_FIELD.MODIFIED_TIME]: this.modified_time, | ||
[MEMBER_ROLE_FIELD.NAME]: this.name, | ||
}; | ||
}; | ||
|
||
toObject = () => { | ||
return {}; | ||
}; | ||
|
||
static __transformItemToApiOfCreation = (data: any) => { | ||
let formData = new FormData(); | ||
const excluded = [MEMBER_ROLE_FIELD.ID]; | ||
Object.keys(MEMBER_ROLE_FIELD).forEach((index) => { | ||
if (!excluded.includes(MEMBER_ROLE_FIELD[index]) && data[MEMBER_ROLE_FIELD[index]]) { | ||
formData.append(MEMBER_ROLE_FIELD[index], data[MEMBER_ROLE_FIELD[index]]); | ||
} | ||
}); | ||
return formData; | ||
}; | ||
|
||
static __transformItemToApiOfUpdation = (data: any) => { | ||
let formData: any = {}; | ||
const excluded = [MEMBER_ROLE_FIELD.CUSTOM_FIELDS]; | ||
Object.keys(MEMBER_ROLE_FIELD).forEach((index) => { | ||
if (!excluded.includes(MEMBER_ROLE_FIELD[index]) && data[MEMBER_ROLE_FIELD[index]]) { | ||
formData[MEMBER_ROLE_FIELD[index]] = data[MEMBER_ROLE_FIELD[index]]; | ||
} | ||
}); | ||
return formData; | ||
}; | ||
} | ||
|
||
export { MemberRoleModel, MemberRoleItemModel }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* @copyright Copyright (C) 2022 AesirX. All rights reserved. | ||
* @license GNU General Public License version 3, see LICENSE. | ||
*/ | ||
|
||
import AesirXApiInstance from '../../Gateway/Instance'; | ||
import BaseRoute from '../../Abstract/BaseRoute'; | ||
import Utils from '../../Utils/Utils'; | ||
|
||
class MemberRoleRouter extends BaseRoute { | ||
option = 'reditem-member_role'; | ||
|
||
create = (data: any) => { | ||
return AesirXApiInstance.post( | ||
this.createRequestURL({ | ||
option: this.option, | ||
}), | ||
data | ||
); | ||
}; | ||
|
||
update = (data: any) => { | ||
return AesirXApiInstance.put( | ||
this.createRequestURL({ | ||
option: this.option, | ||
}), | ||
data, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
delete = (ids: any) => { | ||
return AesirXApiInstance.delete( | ||
this.createRequestURL({ | ||
option: this.option, | ||
}), | ||
{ | ||
data: { ids: Array.isArray(ids) ? ids : [ids] }, | ||
} | ||
); | ||
}; | ||
|
||
getList = (filters: any) => { | ||
const buildFilters = Utils.createFilters(filters); | ||
|
||
return AesirXApiInstance.get( | ||
this.createRequestURL({ | ||
option: this.option, | ||
...buildFilters, | ||
}) | ||
); | ||
}; | ||
|
||
getDetail = (id = 0, dataFilter = {}) => { | ||
return AesirXApiInstance.get( | ||
this.createRequestURL({ | ||
option: this.option, | ||
id: id, | ||
...dataFilter, | ||
}) | ||
); | ||
}; | ||
} | ||
|
||
export default MemberRoleRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { OrganizationMemberApiService } from '../Member'; | ||
import { OrganizationRoleApiService } from '../Role'; | ||
import { MemberRoleApiService } from './index'; | ||
import { describe, expect } from '@jest/globals'; | ||
let createID: any = ''; | ||
let createIDMember: any = ''; | ||
let createIDRole: any = ''; | ||
describe('MemberRole', () => { | ||
it('Get List', async () => { | ||
const service = new MemberRoleApiService(); | ||
|
||
const filters = { | ||
'list[limitstart]': 0, | ||
'list[limit]': 2, | ||
}; | ||
|
||
const data = await service.getList(filters); | ||
|
||
expect(data?.listItems?.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('Create Member', async () => { | ||
const service = new OrganizationMemberApiService(); | ||
|
||
const data = { | ||
member_name: 'Member 0000', | ||
password: 'unittest1', | ||
email: '[email protected]', | ||
role_id: '2', | ||
}; | ||
|
||
const response = await service.create(data); | ||
|
||
createIDMember = response?.result; | ||
|
||
expect(createIDMember).not.toBeNull(); | ||
expect(createIDMember).toBeDefined(); | ||
expect(createIDMember).not.toBeUndefined(); | ||
expect(createIDMember).not.toBe('false'); | ||
}); | ||
|
||
it('Create Role', async () => { | ||
const service = new OrganizationRoleApiService(); | ||
|
||
const data = { | ||
role_name: 'Role 0000', | ||
description: 'description', | ||
}; | ||
|
||
const response = await service.create(data); | ||
|
||
createIDRole = response?.result; | ||
|
||
expect(createIDRole).not.toBeNull(); | ||
expect(createIDRole).toBeDefined(); | ||
expect(createIDRole).not.toBeUndefined(); | ||
expect(createIDRole).not.toBe('false'); | ||
}); | ||
|
||
it('Create', async () => { | ||
const service = new MemberRoleApiService(); | ||
|
||
const data = { | ||
name: 'Member Role 0000', | ||
role_id: createIDRole, | ||
member_id: createIDMember, | ||
state: '1', | ||
}; | ||
|
||
const response = await service.create(data); | ||
|
||
createID = response?.result; | ||
|
||
expect(createID).not.toBeNull(); | ||
expect(createID).toBeDefined(); | ||
expect(createID).not.toBeUndefined(); | ||
expect(createID).not.toBe('false'); | ||
}); | ||
|
||
it('Update', async () => { | ||
const service = new MemberRoleApiService(); | ||
|
||
const data = { | ||
id: createID, | ||
name: 'Member Role 0001', | ||
}; | ||
|
||
const response = await service.update(data); | ||
|
||
expect(response).toBeTruthy(); | ||
}); | ||
|
||
it('Get Detail', async () => { | ||
const service = new MemberRoleApiService(); | ||
|
||
const response: any = await service.getDetail(createID); | ||
|
||
expect(response?.id).toEqual(createID); | ||
}); | ||
|
||
it('Delete', async () => { | ||
const service = new MemberRoleApiService(); | ||
|
||
const response = await service.delete([createID]); | ||
|
||
expect(response).toBeTruthy(); | ||
}); | ||
it('DeleteMember', async () => { | ||
const service = new OrganizationMemberApiService(); | ||
|
||
const response = await service.delete([createIDMember]); | ||
|
||
expect(response).toBeTruthy(); | ||
}); | ||
it('DeleteRole', async () => { | ||
const service = new OrganizationRoleApiService(); | ||
|
||
const response = await service.delete([createIDRole]); | ||
|
||
expect(response).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.