Update availibility migration and add basic crud
This commit is contained in:
parent
cfedf47568
commit
57b66883da
16
api/models/availibilityModel.js
Normal file
16
api/models/availibilityModel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const db = require('../../data/db');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
addAvailibility,
|
||||||
|
deleteAvailibility,
|
||||||
|
};
|
||||||
|
|
||||||
|
function addAvailibility(data) {
|
||||||
|
return db('possible_date')
|
||||||
|
.insert(data)
|
||||||
|
.returning(['id', 'meeting_id', 'possible_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteAvailibility(id) {
|
||||||
|
return db('possible_date').where({ id }).del();
|
||||||
|
}
|
36
api/routes/availibilityRoute.js
Normal file
36
api/routes/availibilityRoute.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
let express = require('express');
|
||||||
|
let router = express.Router();
|
||||||
|
|
||||||
|
let Availibility = require('../models/availibilityModel');
|
||||||
|
|
||||||
|
router.post('/', async (req, res) => {
|
||||||
|
const data = { ...req.body };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [availibility] = await Availibility.addAvailibility(data);
|
||||||
|
res.status(201).json(availibility);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: 'Failed to add a new availibility.',
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete('/:possible_date_id', async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const availibility = await Availibility.deleteAvailibility(id);
|
||||||
|
res.status(200).json({
|
||||||
|
message: `Availibility with id ${id} successfully deleted.`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: `Failed to delete availibility with id ${id}.`,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -7,6 +7,7 @@ const accountsRoute = require('./routes/accountRoute');
|
|||||||
const meetingsRoute = require('./routes/meetingRoute');
|
const meetingsRoute = require('./routes/meetingRoute');
|
||||||
const participantsRoute = require('./routes/participantRoute');
|
const participantsRoute = require('./routes/participantRoute');
|
||||||
const possibleDatesRoute = require('./routes/possibleDateRoute');
|
const possibleDatesRoute = require('./routes/possibleDateRoute');
|
||||||
|
const availibilityRoute = require('./routes/availibilityRoute');
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ server.use('/api/accounts', accountsRoute);
|
|||||||
server.use('/api/meetings', meetingsRoute);
|
server.use('/api/meetings', meetingsRoute);
|
||||||
server.use('/api/participants', participantsRoute);
|
server.use('/api/participants', participantsRoute);
|
||||||
server.use('/api/possible-dates', possibleDatesRoute);
|
server.use('/api/possible-dates', possibleDatesRoute);
|
||||||
|
server.use('/api/availibility', availibilityRoute);
|
||||||
|
|
||||||
server.get('/', (req, res) =>
|
server.get('/', (req, res) =>
|
||||||
res
|
res
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
exports.up = (knex) => {
|
exports.up = (knex) => {
|
||||||
return knex.schema.createTable('availibility', (table) => {
|
return knex.schema.createTable('availibility', (table) => {
|
||||||
table.increments('id').primary();
|
table.increments('id').primary();
|
||||||
|
|
||||||
|
// Reference to participant composite primary key
|
||||||
table.uuid('meeting_id').unsigned();
|
table.uuid('meeting_id').unsigned();
|
||||||
table.integer('account_id').unsigned();
|
table.integer('account_id').unsigned();
|
||||||
table
|
table
|
||||||
@ -8,10 +10,10 @@ exports.up = (knex) => {
|
|||||||
.references(['account_id', 'meeting_id'])
|
.references(['account_id', 'meeting_id'])
|
||||||
.on('participant')
|
.on('participant')
|
||||||
.onDelete('cascade');
|
.onDelete('cascade');
|
||||||
|
|
||||||
|
table.integer('possible_date_id');
|
||||||
table
|
table
|
||||||
.integer('possible_date_id')
|
.foreign('possible_date_id')
|
||||||
.unsigned()
|
|
||||||
.notNullable()
|
|
||||||
.references('possible_date.id')
|
.references('possible_date.id')
|
||||||
.onDelete('cascade');
|
.onDelete('cascade');
|
||||||
table.boolean('preference').notNullable();
|
table.boolean('preference').notNullable();
|
||||||
|
Loading…
Reference in New Issue
Block a user