Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to delete workspace #378

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fadd6e2
resolver added
robonetphy Oct 26, 2021
685d067
mutation added in defination
robonetphy Oct 26, 2021
4930cb9
api added
robonetphy Oct 26, 2021
e748e47
Merge branch 'master' into feature/delete/workspace
robonetphy Oct 26, 2021
b4ea989
Bump version up to 1.0.6
github-actions[bot] Oct 26, 2021
391dc51
Merge branch 'master' into feature/delete/workspace
robonetphy Oct 31, 2021
c724783
Bump version up to 1.0.7
github-actions[bot] Oct 31, 2021
a62bab1
delete workspace added
robonetphy Oct 31, 2021
62bce74
Merge branch 'feature/delete/workspace' of https://github.com/codex-t…
robonetphy Oct 31, 2021
3df315c
the is removed added
robonetphy Nov 3, 2021
305189b
lint removed
robonetphy Nov 3, 2021
c35832c
workspace and project removal undo
robonetphy Nov 4, 2021
d28e394
lint removed
robonetphy Nov 4, 2021
25cdd04
the logic modified
robonetphy Nov 4, 2021
30557c6
the schema modified
robonetphy Nov 4, 2021
d610da5
linting added
robonetphy Nov 4, 2021
c5e77f8
delete project collection in added
robonetphy Nov 4, 2021
f4b9d17
lint removed
robonetphy Nov 4, 2021
560fd03
remove workspace using isRemoved flag
robonetphy Nov 14, 2021
8361c89
remove project using isRemoved flag
robonetphy Nov 14, 2021
65722da
remove deletion of projectToWorkspace Relation
robonetphy Nov 14, 2021
5115652
remove workspace from user using isRemoved flag
robonetphy Nov 14, 2021
1b9b7c3
integration with the delete workspace
robonetphy Nov 14, 2021
e9b802c
lint removed
robonetphy Nov 14, 2021
6af6203
rename the functions
robonetphy Nov 19, 2021
e2f0af3
lint removed
robonetphy Nov 19, 2021
ac47016
$ne=>$exists
robonetphy Dec 7, 2021
f7f0c50
remove teamcollection dropping
robonetphy Dec 7, 2021
4e4fa39
not delete the event factories
robonetphy Dec 7, 2021
0a69fa6
removed lint and event factory
robonetphy Dec 7, 2021
df25814
Merge branch 'master' into feature/delete/workspace
robonetphy Dec 20, 2021
628a86e
Bump version up to 1.0.8
github-actions[bot] Dec 20, 2021
f116fc2
forbidden error remove and replace with return flag
robonetphy Jan 19, 2022
430e4f6
Merge branch 'master' of https://github.com/codex-team/hawk.api.nodej…
neSpecc Jan 21, 2022
bc244c2
remove isAdmin from deleteworkspace
robonetphy Jan 28, 2022
f192ccc
update data loader with not to get isRemoved filed
robonetphy Feb 1, 2022
20c75ce
join by link and invitation link function updated
robonetphy Feb 1, 2022
ee773b8
jsdocs warning resolved
robonetphy Feb 1, 2022
56cb42b
Merge branch 'master' into feature/delete/workspace
robonetphy Feb 1, 2022
b37dfc8
Bump version up to 1.0.9
github-actions[bot] Feb 1, 2022
8d645a1
Merge branch 'master' into feature/delete/workspace
robonetphy Feb 15, 2022
52c2658
Bump version up to 1.0.10
github-actions[bot] Feb 15, 2022
2e99fbd
Merge branch 'master' into feature/delete/workspace
robonetphy Feb 16, 2022
bf1c901
lint removed
robonetphy Feb 16, 2022
cfd7499
Merge branch 'master' into feature/delete/workspace
robonetphy Dec 25, 2022
375d4da
Bump version up to 1.0.23
github-actions[bot] Dec 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.0.6",
"version": "1.0.7",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ export default class WorkspaceModel extends AbstractModel<WorkspaceDBScheme> imp
}
}

/**
* Delete workspace data.
*/
public async deleteWorkspace(): Promise<void> {
/**
* Delete the workspace data.
*/
await this.collection.deleteOne({
_id: new ObjectId(this._id),
});
/**
* Delete the team collection.
*/
await this.teamCollection.drop();
robonetphy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Update invite hash of workspace
* @param inviteHash - new invite hash
Expand Down
56 changes: 56 additions & 0 deletions src/resolvers/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { dateFromObjectId } from '../utils/dates';

const { ApolloError, UserInputError, ForbiddenError } = require('apollo-server-express');
const crypto = require('crypto');
const EventsFactory = require('../models/eventsFactory');

/**
* See all types and fields here {@see ../typeDefs/workspace.graphql}
Expand Down Expand Up @@ -319,6 +320,61 @@ module.exports = {
return true;
},

/**
* Mutation in order to leave workspace
* @param {ResolverObj} _obj - object that contains the result returned from the resolver on the parent field
* @param {string} workspaceId - id of the workspace where the user should be removed
* @param {UserInContext} user - current authorized user {@see ../index.js}
* @param {ContextFactories} factories - factories for working with models
* @return {Promise<boolean>} - true if operation is successful
*/
async deleteWorkspace(_obj, { workspaceId }, { user, factories }) {
const workspaceModel = await factories.workspacesFactory.findById(workspaceId);

if (!workspaceModel) {
throw new UserInputError('There is no workspace with provided id');
}

const memberInfo = await workspaceModel.getMemberInfo(user.id);

if (memberInfo.isAdmin) {
robonetphy marked this conversation as resolved.
Show resolved Hide resolved
const membersInfo = (await workspaceModel.getMembers());

for (const member of membersInfo) {
const userModel = await factories.usersFactory.findById(member.userId.toString());

await workspaceModel.removeMember(userModel);
robonetphy marked this conversation as resolved.
Show resolved Hide resolved
}

const projectToWorkspace = new ProjectToWorkspace(workspaceId);

const projectsInfo = await projectToWorkspace.getProjects();

if (projectsInfo.length) {
for (const project of projectsInfo) {
/**
* Remove project events
*/
await new EventsFactory(project._id).remove();
/**
* Remove project from workspace
*/
await projectToWorkspace.remove(project._id);
/**
* Remove project
*/
const projectModel = await factories.projectsFactory.findById(project.id.toString());

await projectModel.remove();
}
}

await workspaceModel.deleteWorkspace();
}

return true;
},

/**
* Change workspace plan for default plan mutation implementation
*
Expand Down
11 changes: 11 additions & 0 deletions src/typeDefs/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,16 @@ export default gql`
"""
workspaceId: ID!
): Boolean! @requireAuth

"""
Mutation in order to delete workspace
Returns true if operation is successful
"""
deleteWorkspace(
"""
Workspace ID
"""
workspaceId: ID!
): Boolean! @requireAuth
robonetphy marked this conversation as resolved.
Show resolved Hide resolved
}
`;