modif pour image

This commit is contained in:
2024-06-08 15:44:00 +02:00
parent c5477d1ced
commit abd346b150
5 changed files with 108 additions and 49 deletions

View File

@@ -327,19 +327,21 @@ router.put(
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
*
*/
router.put(
"/itm/:tribe/:objectname",
router.delete(
"/itm/:tribe/:objectname/:apxid/:primaryid",
checkHeaders,
isAuthenticated,
(req, res) => {
// Create an item of an object with no specificities
// if specificities then create a route / model that import odmdb
const objectPathname = `../../${req.params.tribe}/objects/${req.params.objectname}`;
const postitm = Odmdb.cud(objectPathname, "U", req.body, {
const itmtoremove={}
itmtoremove[req.params.apxid]=req.params.primaryid;
const delitm = Odmdb.cud(objectPathname, "D", itmtoremove, {
xprofils: req.session.header.xprofils,
xalias: req.session.header.xalias,
});
res.status(postitm.status).json(postitm);
res.status(delitm.status).json(delitm);
}
);

View File

@@ -139,14 +139,12 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
emailregex.test(req.body.email)
)
) {
res
.status(400)
.json({
status: 400,
ref: "Pagans",
msg: "emailerr",
data: { email: req.body.email },
});
res.status(400).json({
status: 400,
ref: "Pagans",
msg: "emailerr",
data: { email: req.body.email },
});
return;
}
const objpagan = { alias: req.body.alias, publickey: req.body.publickey };
@@ -329,12 +327,14 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
* @api {put} /api/adminapi/pagans/person/:tribe - person Put
* @apiName updateperson
* @apiGroup Pagans
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
* @apiDescription add a person = alias in tribe. xalias must be authenticated. This end point have to be use the first time a person is create then use item Update PUT /api/adminapi/odmdb/itm/:tribe/persons.<br> This endpoint is the only way to change profils of a person by itself (authenitcated alias = person.alias) and can be done only with req.body.addprofils req.body.removeprofils.
* @apiHeader {string} xhash authenthicate hash with current user keys
* @apiHeader {string} xalias current user
* @apiHeader {string} xprofils profil list
* @apiParam {object} schema:persons <a href='https://smatchit.io/smatchit/schema/persons.json' target='_blank'>https://dnstribe/tribe/schema/persons.json</a>
*
* @apiParam {string} tribe an existing tribe
* @apiBody {object} schema:persons <a href='https://smatchit.io/smatchit/schema/persons.json' target='_blank'>https://dnstribe/tribe/schema/persons.json</a>
* @apiBody {string} [addprofils] must be alone no other Body field
* @apiBody {string} [removeprofils] must be alone
*/
router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
//console.log(req.body);
@@ -344,24 +344,34 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
: "C";
//set req.body to be in line with schema
if (
action=="U" && req.body.addprofils &&
["seekers", "recruiters", "interviewers"].includes(req.body.addprofils)
action == "U" &&
((req.body.addprofils &&
["seekers", "recruiters", "interviewers"].includes(
req.body.addprofils
)) ||
(req.body.removeprofils &&
["seekers", "recruiters", "interviewers"].includes(
req.body.removeprofils
)))
) {
const person = fs.readJsonSync(`${pathobj}/itm/${req.body.alias}.json`);
if (!person.profils.includes(req.body.addprofils)) {
person.profils.push(req.body.addprofils);
if (req.body.addprofils) {
person.profils.push(req.body.addprofils);
}
if (req.body.removeprofils) {
//@todo
}
}
person.dt_update= dayjs().toISOString();
fs.outputJSONSync(`${pathobj}/itm/${req.body.alias}.json`,person);
console.log(person)
res
.status(200)
.json({
status: 200,
ref: "Pagans",
msg: "profilupdate",
data: { alias:person.alias, profils: person.profils },
});
person.dt_update = dayjs().toISOString();
fs.outputJSONSync(`${pathobj}/itm/${req.body.alias}.json`, person);
//console.log(person)
res.status(200).json({
status: 200,
ref: "Pagans",
msg: "profilupdate",
data: { alias: person.alias, profils: person.profils },
});
}
if (!req.body.addprofils) {
if (!req.body.profils) {
@@ -433,23 +443,19 @@ router.post("/keyrecovery", checkHeaders, (req, res) => {
});
if (emailist.length > 0) {
res
.status(200)
.json({
status: 200,
ref: "Pagans",
msg: "recoveryemailsent",
data: { numberemailsent: emailist.length },
});
res.status(200).json({
status: 200,
ref: "Pagans",
msg: "recoveryemailsent",
data: { numberemailsent: emailist.length },
});
} else {
res
.status(404)
.json({
status: 404,
ref: "Pagans",
msg: "recoveryemailnotfound",
data: { tribe: req.body.tribe },
});
res.status(404).json({
status: 404,
ref: "Pagans",
msg: "recoveryemailnotfound",
data: { tribe: req.body.tribe },
});
}
});

View File

@@ -29,7 +29,7 @@ router.post(
/**
* @api {get} /api/adminapi/wwws/updatelocaldbanonymous/:tribe/:appname/:pagename/:version - Get app data model for anonymous only
* @api {get} /adminapi/wwws/updatelocaldbanonymous/:tribe/:appname/:pagename/:version - Get app data model for anonymous only
* @apiGroup Wwws
* @apiName getappcontextforanonymous
* @apiDescription Get data base from backend to localstorage for anonymous (see Get app data model)
@@ -60,7 +60,7 @@ router.get(
);
/**
* @api {get} /api/adminapi/wwws/updatelocaldb/:tribe/:appname/:pagename/:version - Get app data model
* @api {get} /adminapi/wwws/updatelocaldb/:tribe/:appname/:pagename/:version - Get app data model
* @apiGroup Wwws
* @apiName getappcontext
* @apiDescription Get data base from backend to localstorage for authenticated user