-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
859 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import moduleConfig from "../module.json"; | ||
|
||
export default () => ({ | ||
attachValidation: false, | ||
async handler(req) { | ||
const { | ||
log, | ||
response, | ||
auth, | ||
acl, | ||
} = req.zoia; | ||
// Check permissions | ||
if (!auth.statusAdmin()) { | ||
response.unauthorizedError(); | ||
return; | ||
} | ||
if (!acl.checkPermission(moduleConfig.id, "delete")) { | ||
response.requestAccessDeniedError(); | ||
return; | ||
} | ||
const { | ||
collectionName | ||
} = req.zoiaModulesConfig[moduleConfig.id]; | ||
try { | ||
const result = await this.mongo.db.collection(collectionName).deleteMany({ | ||
deletedAt: { | ||
$ne: null | ||
} | ||
}); | ||
// Check result | ||
if (!result || !result.acknowledged) { | ||
response.deleteError(); | ||
return; | ||
} | ||
// Send "success" result | ||
response.successJSON(); | ||
return; | ||
} catch (e) { | ||
log.error(e); | ||
response.internalServerError(e.message); | ||
} | ||
} | ||
}); |
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,71 @@ | ||
import recycledListData from "./data/recycledList.json"; | ||
import moduleConfig from "../module.json"; | ||
|
||
export default () => ({ | ||
schema: { | ||
body: recycledListData.schema | ||
}, | ||
attachValidation: true, | ||
async handler(req) { | ||
const { | ||
log, | ||
response, | ||
auth, | ||
acl | ||
} = req.zoia; | ||
// Check permissions | ||
if (!auth.statusAdmin()) { | ||
response.unauthorizedError(); | ||
return; | ||
} | ||
// Validate form | ||
if (req.validationError) { | ||
log.error(null, req.validationError.message); | ||
response.validationError(req.validationError); | ||
return; | ||
} | ||
const { | ||
collectionName | ||
} = req.zoiaModulesConfig[moduleConfig.id]; | ||
try { | ||
const options = { | ||
sort: {}, | ||
projection: recycledListData.projection | ||
}; | ||
const query = { | ||
deletedAt: { $ne: null }, | ||
}; | ||
if (req.body.searchText && req.body.searchText.length > 1) { | ||
query.$or = recycledListData.search.map(c => { | ||
const sr = {}; | ||
sr[c] = { | ||
$regex: req.body.searchText, | ||
$options: "i" | ||
}; | ||
return sr; | ||
}); | ||
} | ||
const count = await this.mongo.db.collection(collectionName).find(query, options).count(); | ||
const limit = req.body.itemsPerPage || req.zoiaConfig.commonTableItemsLimit; | ||
options.limit = limit; | ||
options.skip = (req.body.page - 1) * limit; | ||
options.sort[req.body.sortId] = req.body.sortDirection === "asc" ? 1 : -1; | ||
const data = (await this.mongo.db.collection(collectionName).find(query, options).toArray()).map(i => ({ | ||
_id: String(i._id), | ||
deletedAt: !acl.checkPermission(moduleConfig.id, "read", i.deletedAt) ? "***" : i.deletedAt, | ||
title: !acl.checkPermission(moduleConfig.id, "read", i.uid) ? "***" : i.uid, | ||
})); | ||
// Send response | ||
response.successJSON({ | ||
data, | ||
count, | ||
limit, | ||
pagesCount: Math.ceil(count / limit), | ||
}); | ||
return; | ||
} catch (e) { | ||
log.error(e); | ||
response.internalServerError(e.message); | ||
} | ||
} | ||
}); |
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,78 @@ | ||
import { | ||
ObjectId | ||
} from "mongodb"; | ||
import deleteData from "./data/delete.json"; | ||
import moduleConfig from "../module.json"; | ||
|
||
export default () => ({ | ||
schema: { | ||
body: deleteData.root | ||
}, | ||
attachValidation: true, | ||
async handler(req) { | ||
const { | ||
log, | ||
response, | ||
auth, | ||
acl | ||
} = req.zoia; | ||
// Check permissions | ||
if (!auth.statusAdmin()) { | ||
response.unauthorizedError(); | ||
return; | ||
} | ||
// Validate form | ||
if (req.validationError) { | ||
log.error(null, req.validationError.message); | ||
response.validationError(req.validationError); | ||
return; | ||
} | ||
const { | ||
collectionName | ||
} = req.zoiaModulesConfig[moduleConfig.id]; | ||
try { | ||
// Build query | ||
const queryDb = { | ||
$or: req.body.ids.map(id => ({ | ||
_id: new ObjectId(id) | ||
})) | ||
}; | ||
// Get requested data | ||
const dataDb = await this.mongo.db.collection(collectionName).find(queryDb, { | ||
projection: { | ||
uid: 1 | ||
} | ||
}).toArray(); | ||
// Check permission | ||
let allowed = true; | ||
(dataDb || []).map(i => { | ||
if (allowed && !acl.checkPermission(moduleConfig.id, "delete", i.uid)) { | ||
allowed = false; | ||
} | ||
}); | ||
if (!allowed) { | ||
response.requestAccessDeniedError(); | ||
return; | ||
} | ||
// Restore requested IDs | ||
const result = await this.mongo.db.collection(collectionName).updateMany(queryDb, { | ||
$set: { | ||
deletedAt: null | ||
} | ||
}, { | ||
upsert: false | ||
}); | ||
// Check result | ||
if (!result || !result.acknowledged) { | ||
response.deleteError(); | ||
return; | ||
} | ||
// Send "success" result | ||
response.successJSON(); | ||
return; | ||
} catch (e) { | ||
log.error(e); | ||
response.internalServerError(e.message); | ||
} | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"page": { | ||
"type": "number", | ||
"minimum": 1, | ||
"maximum": 999999 | ||
}, | ||
"sortId": { | ||
"type": "string", | ||
"enum": ["title", "deletedAt"] | ||
}, | ||
"sortDirection": { | ||
"type": "string", | ||
"enum": ["asc", "desc"] | ||
}, | ||
"searchText": { | ||
"type": "string", | ||
"minLength": 0, | ||
"maxLength": 128 | ||
}, | ||
"itemsPerPage": { | ||
"type": "number", | ||
"minimum": 0, | ||
"maximum": 1000 | ||
}, | ||
"autoItemsPerPage": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": ["page", "sortId", "sortDirection"] | ||
}, | ||
"projection": { | ||
"_id": 1, | ||
"uid": 1, | ||
"deletedAt": 1 | ||
}, | ||
"search": ["uid"] | ||
} |
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
Oops, something went wrong.