mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-21 20:28:11 +01:00
added new api routes to frontend api controller
This commit is contained in:
parent
c1cba31d06
commit
baf5d30f8b
1 changed files with 104 additions and 7 deletions
111
src/api.js
111
src/api.js
|
@ -1,6 +1,31 @@
|
||||||
import axios from "@nextcloud/axios"
|
import axios from "@nextcloud/axios"
|
||||||
import { generateUrl } from "@nextcloud/router"
|
import { generateUrl } from "@nextcloud/router"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {number} PrincipalType
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {PrincipalType}
|
||||||
|
*/
|
||||||
|
var PrincipalTypes = {
|
||||||
|
USER: 1,
|
||||||
|
GROUP: 2,
|
||||||
|
ROLE: 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {number} ResourceMemberPermissionLevel
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {ResourceMemberPermissionLevel}
|
||||||
|
*/
|
||||||
|
var ResourceMemberPermissionLevels = {
|
||||||
|
MEMBER: 1,
|
||||||
|
MANAGER: 2,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* id: number
|
* id: number
|
||||||
|
@ -18,24 +43,33 @@ import { generateUrl } from "@nextcloud/router"
|
||||||
* @typedef {(FolderResource)} Resource
|
* @typedef {(FolderResource)} Resource
|
||||||
*
|
*
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* type: number,
|
* type: PrincipalType,
|
||||||
* id: string,
|
* id: string,
|
||||||
* }} Principal
|
* }} Principal
|
||||||
*
|
*
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* id: number
|
* id: number
|
||||||
* resourceId: number
|
* resourceId: number
|
||||||
* permissionLevel: number
|
* permissionLevel: ResourceMemberPermissionLevel
|
||||||
* principal: Principal,
|
* principal: Principal,
|
||||||
* createdTimestamp: number,
|
* createdTimestamp: number,
|
||||||
* lastUpdatedTimestamp: number,
|
* lastUpdatedTimestamp: number,
|
||||||
* }} ResourceMember
|
* }} ResourceMember
|
||||||
*
|
*
|
||||||
|
* @typedef {{
|
||||||
|
* id: number,
|
||||||
|
* friendlyName: string,
|
||||||
|
* membersGroup: string,
|
||||||
|
* }} Organization
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
axios.defaults.baseURL = generateUrl("/apps/organization_folders")
|
axios.defaults.baseURL = generateUrl("/apps/organization_folders")
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
PrincipalTypes,
|
||||||
|
ResourceMemberPermissionLevels,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {number|string} resourceId Resource id
|
* @param {number|string} resourceId Resource id
|
||||||
|
@ -43,7 +77,7 @@ export default {
|
||||||
* @return {Promise<Resource>}
|
* @return {Promise<Resource>}
|
||||||
*/
|
*/
|
||||||
getResource(resourceId, include = "model") {
|
getResource(resourceId, include = "model") {
|
||||||
return axios.get(`/resources/${resourceId}`, { params: { include } }).then((res) => res.data)
|
return axios.get(`/resources/${resourceId}`, { params: { include } }).then((res) => res.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,16 +92,79 @@ export default {
|
||||||
* }} updateResourceDto UpdateResourceDto
|
* }} updateResourceDto UpdateResourceDto
|
||||||
* @return {Promise<Resource>}
|
* @return {Promise<Resource>}
|
||||||
*/
|
*/
|
||||||
updateResource(resourceId, updateGroupDto) {
|
updateResource(resourceId, updateGroupDto, include = "model") {
|
||||||
return axios.put(`/resources/${resourceId}`, { ...updateGroupDto }).then((res) => res.data)
|
return axios.put(`/resources/${resourceId}`, { ...updateGroupDto, include }).then((res) => res.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {number|string} resourceId Resource id
|
* @param {number|string} resourceId Resource id
|
||||||
* @return {Promise<Array<ResourceMember>>}
|
* @return {Promise<Array<ResourceMember>>}
|
||||||
*/
|
*/
|
||||||
getResourceMembers(resourceId) {
|
getResourceMembers(resourceId) {
|
||||||
return axios.get(`/resources/${resourceId}/members`, {}).then((res) => res.data)
|
return axios.get(`/resources/${resourceId}/members`, {}).then((res) => res.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number|string} resourceId Resource id
|
||||||
|
* @param {{
|
||||||
|
* permissionLevel: ResourceMemberPermissionLevel
|
||||||
|
* principalType: PrincipalType
|
||||||
|
* principalId: string
|
||||||
|
* }} createResourceMemberDto CreateResourceMemberDto
|
||||||
|
* @return {Promise<ResourceMember>}
|
||||||
|
*/
|
||||||
|
createResourceMember(resourceId, createResourceMemberDto) {
|
||||||
|
return axios.post(`/resources/${resourceId}/members`, { ...createResourceMemberDto }).then((res) => res.data);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number|string} resourceMemberId Resource member id
|
||||||
|
* @param {{
|
||||||
|
* permissionLevel: ResourceMemberPermissionLevel
|
||||||
|
* }} createResourceMemberDto CreateResourceMemberDto
|
||||||
|
* @return {Promise<ResourceMember>}
|
||||||
|
*/
|
||||||
|
updateResourceMember(resourceId, createResourceMemberDto) {
|
||||||
|
return axios.post(`/resources/${resourceId}/members`, { ...createResourceMemberDto }).then((res) => res.data);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Promise<Array<string>>}
|
||||||
|
*/
|
||||||
|
getOrganizationProviders() {
|
||||||
|
return axios.get(`/organizationProviders`, {}).then((res) => res.data);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} organizationProviderId organization provider id
|
||||||
|
* @param {int} id organization id
|
||||||
|
* @return {Promise<Organization>}
|
||||||
|
*/
|
||||||
|
getOrganization(organizationProviderId, id) {
|
||||||
|
return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${id}`, { }).then((res) => res.data);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} organizationProviderId organization provider id
|
||||||
|
* @param {number|undefined} parentOrganizationId parent organization id (null if top level organizations)
|
||||||
|
* @return {Promise<Array<Organization>>}
|
||||||
|
*/
|
||||||
|
getSubOrganizations(organizationProviderId, parentOrganizationId) {
|
||||||
|
if(parentOrganizationId) {
|
||||||
|
return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${parentOrganizationId}/subOrganizations`, { }).then((res) => res.data);
|
||||||
|
} else {
|
||||||
|
return axios.get(`/organizationProviders/${organizationProviderId}/subOrganizations`, { }).then((res) => res.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} organizationProviderId organization provider id
|
||||||
|
* @param {number} organizationId organization id
|
||||||
|
* @return {Promise<Array<Organization>>}
|
||||||
|
*/
|
||||||
|
getRoles(organizationProviderId, organizationId) {
|
||||||
|
return axios.get(`/organizationProviders/${organizationProviderId}/organizations/${organizationId}/roles/`, { }).then((res) => res.data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue