Commit e13d4feb authored by Elena Tsoy's avatar Elena Tsoy

внесены изменения в фикстуры и server для демо

parent 35ce0f04
......@@ -99,7 +99,7 @@ const createRouter = () => {
});
router.get('/:id/paid', [auth, permit('payPayment')], async (req, res) => {
const payment = await Payment.findById(req.params.id)
const payment = await Payment.findById(req.params.id).populate('user', 'surname name workEmail')
if (payment.approved) {
payment.paided = true;
} else {
......@@ -170,7 +170,26 @@ const createRouter = () => {
res.status(500).send(e);
}
});
router.get('/files/today', [auth, permit('payPayment')], async (req, res) => {
let filter = {
dateOfPayment: {
$lte: moment().format('YYYY-MM-DD')
},
approved: true
};
try {
const payments = await Payment.find(filter).populate('user', 'surname name workEmail');
let files = []
payments.map(p=>{
if(p.image){
files.push(p.image)
}
})
res.send(files);
} catch (e) {
res.status(500).send(e);
}
});
router.get('/due/to-be-paid', [auth, permit('viewToBePaid')], async (req, res) => {
let filter = { paided: false, approved: true };
try {
......
......@@ -22,7 +22,7 @@ db.once('open', async () => {
telegramName: "@IvanIvanov",
phone: "+7 777 77 77 77",
password: "12345a",
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'initCancelApprovedPayment', 'viewUsers', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'initCancelApprovedPayment', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
token: [nanoid(), nanoid()]
}, {
workEmail: "accountant@accountant.com",
......@@ -33,7 +33,7 @@ db.once('open', async () => {
telegramName: "@OlgaPetrova",
phone: "+7 555 555 55 55",
password: "12345a",
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'payPayment', 'viewToBePaid', 'viewTodayPayments', 'initCancelApprovedPayment', 'initCancelPayedPayment', 'cancelPayedPayment', 'viewUsers', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'payPayment', 'viewToBePaid', 'viewTodayPayments', 'initCancelApprovedPayment', 'initCancelPayedPayment', 'cancelPayedPayment', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
token: [nanoid(), nanoid()]
}, {
workEmail: "director@director.com",
......@@ -44,7 +44,7 @@ db.once('open', async () => {
telegramName: "@director",
phone: "+7 555 555 55 55",
password: "12345a",
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'approvePayment', 'payPayment', 'postponePayment', 'viewTodayPayments', 'initCancelApprovedPayment', 'cancelApprovedPayment', 'initCancelPayedPayment', 'cancelPayedPayment', 'deletePayment', 'authorizeUser', 'editUser', 'deleteUser', 'viewUsers', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'approvePayment', 'postponePayment', 'viewTodayPayments', 'initCancelApprovedPayment', 'cancelApprovedPayment', 'initCancelPayedPayment', 'deletePayment', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
token: [nanoid(), nanoid()]
}, {
workEmail: "admin@admin.com",
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ const users = require('./app/users');
const payments = require('./app/payments');
const meetings = require('./app/meetings');
const cors = require('cors');
// const config = require('./app/config');
const config = require('./app/config');
const User = require('./app/models/User');
// const { nanoid } = require('nanoid');
const mongo=require('./app/db');
......@@ -22,8 +22,9 @@ app.use(express.json());
app.use(express.static('public'));
const run = async () => {
mongo.mongoConnect();
await mongoose.connect(config.db.url+'/'+config.db.name, {useNewUrlParser:true, useUnifiedTopology: true}) //добавлено для демо
// mongo.mongoConnect();
app.use('/meetings', meetings());
app.use('/payments', payments());
......@@ -33,32 +34,30 @@ const run = async () => {
app.listen(port, () => {
console.log(`Server started on port ${port}!`)
})
const db = mongoose.connection;
db.once('open', async () => {
try {
await db.dropCollection('users');
} catch (e) {
console.log('Collection were not present, skipping drop...')
}
await User.create({
workEmail: "admin@admin.com",
surname: "Admin",
name: "Admin",
patronymic: "Admin",
position: "admin",
telegramName: "@admin",
phone: "+7 555 555 55 55",
password: "12345a",
role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'approvePayment', 'payPayment', 'postponePayment', 'viewToBePaid', 'viewTodayPayments', 'initCancelApprovedPayment', 'cancelApprovedPayment', 'initCancelPayedPayment', 'cancelPayedPayment', 'deletePayment', 'authorizeUser', 'editUser', 'deleteUser', 'viewUsers', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
token: ['adminToken', 'adminToken']
});
})
console.log('fixtures connected');
console.log('Mongoose connected!'); //добавлено для демо
module.exports =app;
// const db = mongoose.connection;
// db.once('open', async () => {
// try {
// await db.dropCollection('users');
// } catch (e) {
// console.log('Collection were not present, skipping drop...')
// }
// await User.create({
// workEmail: "admin@admin.com",
// surname: "Admin",
// name: "Admin",
// patronymic: "Admin",
// position: "admin",
// telegramName: "@admin",
// phone: "+7 555 555 55 55",
// password: "12345a",
// role: ['viewAllPayments', 'stopRepeatabilityPayment', 'addPayment', 'editPayment', 'approvePayment', 'payPayment', 'postponePayment', 'viewToBePaid', 'viewTodayPayments', 'initCancelApprovedPayment', 'cancelApprovedPayment', 'initCancelPayedPayment', 'cancelPayedPayment', 'deletePayment', 'authorizeUser', 'editUser', 'deleteUser', 'viewUsers', 'bookMeetingRoom', 'editBookedMeetingRoom', 'deleteBookedMeetingRoom', 'viewBookingsMeetingRoom'],
// token: ['adminToken', 'adminToken']
// });
// })
// console.log('fixtures connected');
// module.exports =app;
};
run().catch(console.log);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment