MCPcopy
hub / github.com/caprover/caprover / deleteProject

Method deleteProject

src/datastore/ProjectsDataStore.ts:202–244  ·  view source on GitHub ↗
(projectId: string)

Source from the content-addressed store, hash-verified

200 }
201
202 deleteProject(projectId: string) {
203 const self = this
204
205 projectId = `${projectId || ''}`.trim()
206
207 return Promise.resolve()
208 .then(function () {
209 // dumb configstore needs some time to store the file!!!
210 // otherwise (in case multiple deletes), the child deletion is not committed yet
211 return Utils.getDelayedPromise(500)
212 })
213 .then(function () {
214 return self.getProject(projectId)
215 })
216 .then(function (project) {
217 // project exists
218
219 return self.appsDataStore.getAppDefinitions()
220 })
221 .then(function (appsAll) {
222 const apps = Object.keys(appsAll).map((key) => appsAll[key])
223
224 if (apps.some((app) => app.projectId === projectId)) {
225 throw ApiStatusCodes.createError(
226 ApiStatusCodes.ILLEGAL_OPERATION,
227 'Project is not empty (has apps)'
228 )
229 }
230 })
231 .then(function () {
232 return self.getAllProjects()
233 })
234 .then(function (allProjects) {
235 if (allProjects.some((p) => p.parentProjectId === projectId)) {
236 throw ApiStatusCodes.createError(
237 ApiStatusCodes.ILLEGAL_OPERATION,
238 'Project is not empty (has sub projects)'
239 )
240 }
241
242 return self.data.delete(`${PROJECTS_DEFINITIONS}.${projectId}`)
243 })
244 }
245}
246
247export default ProjectsDataStore

Callers 1

deleteProjectsMethod · 0.80

Calls 5

getDelayedPromiseMethod · 0.80
getProjectMethod · 0.80
getAppDefinitionsMethod · 0.80
createErrorMethod · 0.80
getAllProjectsMethod · 0.80

Tested by

no test coverage detected