-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(state): create organization service/state
- Loading branch information
1 parent
214a52a
commit 430741a
Showing
11 changed files
with
159 additions
and
23 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
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
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
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
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 |
---|---|---|
@@ -1,27 +1,73 @@ | ||
import { reactive, readonly, toRefs } from "vue"; | ||
import OrganizationService from "@/services/OrganizationService.js"; | ||
|
||
const state = reactive({ | ||
userOrganizations: [], | ||
organizationSpaces: [] | ||
}); | ||
|
||
const retrieveOrganizations = async () => { | ||
return await OrganizationService.retrieveOrganizations(); | ||
const organizations = await OrganizationService.fetchOrganizations(); | ||
state.userOrganizations = organizations; | ||
return organizations; | ||
}; | ||
|
||
const fecthOrganizationSpaces = async organization => { | ||
const spaces = await OrganizationService.fecthOrganizationSpaces( | ||
organization | ||
); | ||
state.organizationSpaces = spaces; | ||
return spaces; | ||
}; | ||
|
||
const createOrganization = async organization => { | ||
const newOrganization = await OrganizationService.createOrganization( | ||
organization | ||
); | ||
state.userOrganizations = [newOrganization].concat(state.userOrganizations); | ||
return newOrganization; | ||
}; | ||
|
||
const updateOrganization = async organization => { | ||
const newOrganization = await OrganizationService.updateOrganization( | ||
organization | ||
); | ||
softUpdateOrganization(newOrganization); | ||
return newOrganization; | ||
}; | ||
|
||
const createOrganization = async () => { | ||
// TODO | ||
const deleteOrganization = async organization => { | ||
await OrganizationService.deleteOrganization(organization); | ||
softDeleteOrganization(organization); | ||
return organization; | ||
}; | ||
|
||
const updateOrganization = async () => { | ||
// TODO | ||
const softUpdateOrganization = organization => { | ||
state.userOrganizations = state.userOrganizations.map(orga => | ||
orga.id === organization.id ? { ...orga, ...organization } : orga | ||
); | ||
return organization; | ||
}; | ||
|
||
const deleteOrganization = async () => { | ||
// TODO | ||
const softDeleteOrganization = organization => { | ||
state.userOrganizations = state.userOrganizations.filter( | ||
orga => orga.id !== organization.id | ||
); | ||
return organization; | ||
}; | ||
|
||
export function useOrganizations() { | ||
const readonlyState = readonly(state); | ||
return { | ||
// References | ||
...toRefs(readonlyState), | ||
// Methods | ||
retrieveOrganizations, | ||
fecthOrganizationSpaces, | ||
createOrganization, | ||
updateOrganization, | ||
deleteOrganization | ||
deleteOrganization, | ||
softUpdateOrganization, | ||
softDeleteOrganization | ||
}; | ||
} |
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