feat: admin add user

This commit is contained in:
archer
2023-07-20 10:56:57 +08:00
parent 82e7776a77
commit 6d358ef3e6
8 changed files with 1411 additions and 2279 deletions

View File

@@ -46,63 +46,6 @@ export const useSystemRoute = (app) => {
res.status(401).end('username or password incorrect');
}
});
app.get('/system', auth(), async (req, res) => {
try {
const data = await System.find();
const totalCount = await System.countDocuments();
res.header('Access-Control-Expose-Headers', 'X-Total-Count');
res.header('X-Total-Count', totalCount);
res.json(
data.map((item) => {
const obj = item.toObject();
return {
...obj,
id: obj._id
};
})
);
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Error creating system env' });
}
});
app.post('/system', auth(), async (req, res) => {
try {
await System.create({
...req.body,
sensitiveCheck: req.body.sensitiveCheck === 'true'
});
postParent();
res.json({});
} catch (error) {
res.status(500).json({ error: 'Error creating system env' });
}
});
app.put('/system/:id', auth(), async (req, res) => {
try {
const _id = req.params.id;
await System.findByIdAndUpdate(_id, {
...req.body,
sensitiveCheck: req.body.sensitiveCheck === 'true'
});
postParent();
res.json({});
} catch (error) {
res.status(500).json({ error: 'Error updating system env' });
}
});
app.delete('/system/:id', auth(), async (req, res) => {
try {
const _id = req.params.id;
await System.findByIdAndDelete(_id);
res.json({});
} catch (error) {
res.status(500).json({ error: 'Error updating system env' });
}
});
};
export const auth = () => {
@@ -110,7 +53,7 @@ export const auth = () => {
try {
const authorization = req.headers.authorization;
if (!authorization) {
return next(new Error("unAuthorization"))
return next(new Error('unAuthorization'));
}
const token = authorization.slice('Bearer '.length);