Whatever
This commit is contained in:
@@ -52,6 +52,7 @@ checkAuth = passport.authenticate('jwt', { session: false });
|
||||
app.use(checkAuth);
|
||||
|
||||
// ROUTES WITH AUTH
|
||||
app.use('/campaign', require('./routes/campaign'));
|
||||
/*
|
||||
app.use('/campaign', require('./routes/campaign'));
|
||||
app.use('/maps', require('./routes/map'));
|
||||
|
||||
17
backend/src/models/Campaign.js
Normal file
17
backend/src/models/Campaign.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const mongoose = require("mongoose");
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const CampaignSchema = new Schema({
|
||||
name: {type: String, required: true},
|
||||
description: {type: String},
|
||||
color: {type: String},
|
||||
createdBy: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
required: true
|
||||
},
|
||||
date: { type: Date, default: Date.now},
|
||||
settings: { type: Object }
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Campaign', CampaignSchema);
|
||||
32
backend/src/routes/campaign.js
Normal file
32
backend/src/routes/campaign.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const express = require('express')
|
||||
const router = express.Router();
|
||||
|
||||
const Campaign = require("../models/Campaign");
|
||||
|
||||
router.post('/create', async (req, res) => {
|
||||
try {
|
||||
const { name, description, color, settings } = req.body;
|
||||
const newCampaign = new Campaign({
|
||||
name,
|
||||
description,
|
||||
color,
|
||||
settings,
|
||||
createdBy: req.user.id
|
||||
});
|
||||
await newCampaign.save();
|
||||
res.json({ status: "ok", campaign: newCampaign });
|
||||
} catch (err) {
|
||||
res.json({ status: "error", msg: "errors.internal" });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/list', async (req, res) => {
|
||||
try {
|
||||
const campaigns = await Campaign.find({ createdBy: req.user.id });
|
||||
res.json({ status: "ok", campaigns });
|
||||
} catch (err) {
|
||||
res.json({ status: "error", msg: "errors.internal", err });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user