File uploading, other tweaks.

This commit is contained in:
oitsjustjose 2020-07-04 23:35:15 -05:00
commit 3f461319b3
7 changed files with 102 additions and 180 deletions

View file

@ -1,6 +1,8 @@
import { Application } from "express"
import { PassportStatic } from "passport"
import * as Auth from './auth'
import ConfigDB from '../models/config.model'
export const init = (app: Application, passport: PassportStatic) => {
app.get('/', async (req, res) => {
@ -10,15 +12,32 @@ export const init = (app: Application, passport: PassportStatic) => {
})
app.put('/', async (req, res) => {
if (req.isAuthenticated() && req.user) {
req.user.configs.push({
name: req.body.name,
conf: req.body.config
try {
const conf = new ConfigDB()
conf.json = req.body.config
conf.name = req.body.name
await conf.save()
if (req.isAuthenticated() && req.user) {
req.user.configs.push({
name: req.body.name,
conf: conf._id
})
}
res.status(200).send(conf)
} catch (ex) {
res.status(500).send({
error: ex
})
}
})
app.get('/configs/:id', async (req, res) => {
const conf = await ConfigDB.findById(req.params.id)
if (conf) {
res.json(conf.json)
} else {
res.status(401).send({
error: 'Not logged in!'
})
res.status(404).end()
}
})