Correct typo: "availibility" => "availability
This commit is contained in:
parent
ca0bd47ed8
commit
3f6ff08e6c
@ -1,12 +1,12 @@
|
|||||||
const db = require('../../data/db');
|
const db = require('../../data/db');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addAvailibility,
|
addAvailability,
|
||||||
deleteAvailibility,
|
deleteAvailability,
|
||||||
};
|
};
|
||||||
|
|
||||||
function addAvailibility(data) {
|
function addAvailability(data) {
|
||||||
return db('availibility')
|
return db('availability')
|
||||||
.insert(data)
|
.insert(data)
|
||||||
.returning([
|
.returning([
|
||||||
'id',
|
'id',
|
||||||
@ -20,6 +20,6 @@ function addAvailibility(data) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteAvailibility(id) {
|
function deleteAvailability(id) {
|
||||||
return db('availibility').where({ id }).del();
|
return db('availability').where({ id }).del();
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ module.exports = {
|
|||||||
deleteMeeting,
|
deleteMeeting,
|
||||||
getParticipantsByMeetingId,
|
getParticipantsByMeetingId,
|
||||||
getPossibleDatesByMeetingId,
|
getPossibleDatesByMeetingId,
|
||||||
getAvailibilityByMeetingId,
|
getAvailabilityByMeetingId,
|
||||||
};
|
};
|
||||||
|
|
||||||
function addMeeting(data) {
|
function addMeeting(data) {
|
||||||
@ -82,8 +82,8 @@ function getPossibleDatesByMeetingId(meeting_id) {
|
|||||||
.where({ meeting_id });
|
.where({ meeting_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAvailibilityByMeetingId(meeting_id) {
|
function getAvailabilityByMeetingId(meeting_id) {
|
||||||
return db('availibility as a')
|
return db('availability as a')
|
||||||
.select(
|
.select(
|
||||||
'a.id',
|
'a.id',
|
||||||
'a.meeting_id',
|
'a.meeting_id',
|
||||||
|
@ -2,17 +2,17 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const { authenticate } = require('../../middlewares/authenticate');
|
const { authenticate } = require('../../middlewares/authenticate');
|
||||||
const Availibility = require('../models/availibilityModel');
|
const Availability = require('../models/availabilityModel');
|
||||||
|
|
||||||
router.post('/', authenticate, async (req, res) => {
|
router.post('/', authenticate, async (req, res) => {
|
||||||
const data = { ...req.body };
|
const data = { ...req.body };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [availibility] = await Availibility.addAvailibility(data);
|
const [availability] = await Availability.addAvailability(data);
|
||||||
res.status(201).json(availibility);
|
res.status(201).json(availability);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: 'Failed to add a new availibility.',
|
message: 'Failed to add a new availability.',
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -22,13 +22,13 @@ router.delete('/:id', authenticate, async (req, res) => {
|
|||||||
const id = req.params.id;
|
const id = req.params.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const availibility = await Availibility.deleteAvailibility(id);
|
const availability = await Availability.deleteAvailability(id);
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: `Availibility with id ${id} successfully deleted.`,
|
message: `Availability with id ${id} successfully deleted.`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
message: `Failed to delete availibility with id ${id}.`,
|
message: `Failed to delete availability with id ${id}.`,
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -130,24 +130,29 @@ router.get(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get('/:id/availibility', authenticate, validateMeetingID, async (req, res) => {
|
router.get(
|
||||||
const id = req.params.id;
|
'/:id/availability',
|
||||||
|
authenticate,
|
||||||
|
validateMeetingID,
|
||||||
|
async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const availibility = await Meeting.getAvailibilityByMeetingId(id);
|
const availability = await Meeting.getAvailabilityByMeetingId(id);
|
||||||
if (availibility.length == 0) {
|
if (availability.length == 0) {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: `There are no possibles dates for meeting with id ${id}.`,
|
message: `There are no possibles dates for meeting with id ${id}.`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(200).json(availability);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({
|
||||||
|
message: `Failed to fetch availability for meeting with id ${id}`,
|
||||||
|
error,
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
res.status(200).json(availibility);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
},
|
||||||
res.status(500).json({
|
);
|
||||||
message: `Failed to fetch availibility for meeting with id ${id}`,
|
|
||||||
error,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
@ -8,7 +8,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 availabilityRoute = require('./routes/availabilityRoute');
|
||||||
const authRoute = require('./routes/authRoute');
|
const authRoute = require('./routes/authRoute');
|
||||||
|
|
||||||
const server = express();
|
const server = express();
|
||||||
@ -31,7 +31,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.use('/api/availability', availabilityRoute);
|
||||||
server.use('/api/auth', authRoute);
|
server.use('/api/auth', authRoute);
|
||||||
|
|
||||||
server.get('/', (req, res) =>
|
server.get('/', (req, res) =>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
exports.up = (knex) => {
|
exports.up = (knex) => {
|
||||||
return knex.schema.createTable('availibility', (table) => {
|
return knex.schema.createTable('availability', (table) => {
|
||||||
table.increments('id').primary();
|
table.increments('id').primary();
|
||||||
|
|
||||||
// Reference to participant composite primary key
|
// Reference to participant composite primary key
|
||||||
@ -25,5 +25,5 @@ exports.up = (knex) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.down = (knex) => {
|
exports.down = (knex) => {
|
||||||
return knex.schema.dropTable('availibility');
|
return knex.schema.dropTable('availability');
|
||||||
};
|
};
|
@ -1,10 +1,10 @@
|
|||||||
exports.seed = function (knex) {
|
exports.seed = function (knex) {
|
||||||
// Deletes ALL existing entries
|
// Deletes ALL existing entries
|
||||||
return knex('availibility')
|
return knex('availability')
|
||||||
.del()
|
.del()
|
||||||
.then(function () {
|
.then(function () {
|
||||||
// Inserts seed entries
|
// Inserts seed entries
|
||||||
return knex('availibility').insert([
|
return knex('availability').insert([
|
||||||
// Meeting 1 - Day 1
|
// Meeting 1 - Day 1
|
||||||
{
|
{
|
||||||
account_id: 1,
|
account_id: 1,
|
Loading…
Reference in New Issue
Block a user