changes in kurir and pengaturanbiayakurir schema for ref and kurir search api
This commit is contained in:
@ -29,29 +29,35 @@ async function cek_user_kurir(req, res, next) {
|
||||
|
||||
// create '/pengaturan' post route
|
||||
router.post('/pengaturan', cek_user_kurir, async (req, res) => {
|
||||
// console.log('masuk post pengaturan');
|
||||
console.log('masuk post pengaturan');
|
||||
const minimal_biaya_pengiriman = req.body.minimal_biaya_pengiriman;
|
||||
const maksimal_biaya_pengiriman = req.body.maksimal_biaya_pengiriman;
|
||||
const biaya_per_kilo = req.body.biaya_per_kilo;
|
||||
|
||||
const cek_data = await pengaturanPengirimanModel.findOne({
|
||||
id_kurir: req.query.id
|
||||
kurir: req.query.id
|
||||
});
|
||||
let message, datanya;
|
||||
if (cek_data) {
|
||||
datanya = await pengaturanPengirimanModel.findOneAndUpdate({
|
||||
id_kurir: req.query.id,
|
||||
kurir: req.query.id,
|
||||
}, {
|
||||
biaya_minimal: minimal_biaya_pengiriman,
|
||||
biaya_maksimal: maksimal_biaya_pengiriman,
|
||||
biaya_per_kilo: biaya_per_kilo,
|
||||
updated_at: new Date()
|
||||
})
|
||||
|
||||
await kurirModel.findOneAndUpdate({
|
||||
_id: req.query.id
|
||||
},{
|
||||
pengaturan_pengiriman: datanya._id
|
||||
})
|
||||
message = 'Pengaturan pengiriman berhasil diubah';
|
||||
|
||||
} else {
|
||||
datanya = new pengaturanPengirimanModel({
|
||||
id_kurir: req.query.id,
|
||||
kurir : req.query.id,
|
||||
biaya_minimal: minimal_biaya_pengiriman,
|
||||
biaya_maksimal: maksimal_biaya_pengiriman,
|
||||
biaya_per_kilo,
|
||||
@ -59,6 +65,14 @@ router.post('/pengaturan', cek_user_kurir, async (req, res) => {
|
||||
updated_at: new Date()
|
||||
});
|
||||
await datanya.save();
|
||||
await kurirModel.findOneAndUpdate({
|
||||
_id: req.query.id
|
||||
},{
|
||||
pengaturan_pengiriman: datanya._id
|
||||
})
|
||||
|
||||
// save to pengaturanPengirimanModel reference to kurirModel
|
||||
|
||||
message = 'Pengaturan biaya pengiriman berhasil dibuat';
|
||||
console.log("data baru");
|
||||
}
|
||||
@ -68,9 +82,10 @@ router.post('/pengaturan', cek_user_kurir, async (req, res) => {
|
||||
|
||||
// create '/pengaturan' get route
|
||||
router.get('/pengaturan', cek_user_kurir, async (req, res) => {
|
||||
// console.log('masuk get pengaturan');
|
||||
// router.get('/pengaturan', async (req, res) => {
|
||||
console.log('masuk get pengaturan');
|
||||
const cek_data = await pengaturanPengirimanModel.findOne({
|
||||
id_kurir: req.query.id
|
||||
kurir: req.query.id
|
||||
});
|
||||
if (!cek_data) return res.status(200).send({ message: 'Pengaturan tidak ditemukan' , data: null});
|
||||
res.status(200).send({ message: 'Pengaturan pengiriman berhasil ditemukan', data: cek_data });
|
||||
|
||||
@ -144,9 +144,19 @@ router.post('/daftar1', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
res.send({ status: true, message: 'Anda akan mendapat notifikasi di email anda dan juga no telpon jika admin menyetujui ataupun membatalkan pendaftaran anda' });
|
||||
|
||||
console.log(data)
|
||||
let new_kurir = new kurirModel(data);
|
||||
|
||||
let new_login = new loginUserModel(data);
|
||||
new_login._idnya = new_kurir._id;
|
||||
await new_kurir.save();
|
||||
await new_login.save();
|
||||
console.log(new_kurir)
|
||||
console.log(new_login)
|
||||
|
||||
|
||||
// add photo_url to new_kurir
|
||||
let id_photo = googlenya.uploadFile(new_kurir._id + ".jpg", req.files.photo.path, kurir_folder_id, "ini photo kurir");
|
||||
|
||||
@ -163,22 +173,32 @@ router.post('/daftar1', async (req, res) => {
|
||||
// add kenderaan_url to kurir
|
||||
let id_kenderaan = googlenya.uploadFile("kenderaan_" + new_kurir._id + ".jpg", req.files.kenderaan_photo.path, kenderaan_kurir_folder_id, "ini kenderaan kurir");
|
||||
|
||||
new_kurir.photo_url = `https://drive.google.com/uc?export=view&id=${await id_photo}`
|
||||
new_kurir.ktp_url = `https://drive.google.com/uc?export=view&id=${await id_ktp}`
|
||||
new_kurir.ktp_holding_url = `https://drive.google.com/uc?export=view&id=${await id_ktp_holding}`
|
||||
new_kurir.kenderaan_url = `https://drive.google.com/uc?export=view&id=${await id_kenderaan}`
|
||||
const photo_url = `https://drive.google.com/uc?export=view&id=${await id_photo}`
|
||||
const ktp_url = `https://drive.google.com/uc?export=view&id=${await id_ktp}`
|
||||
const ktp_holding_url = `https://drive.google.com/uc?export=view&id=${await id_ktp_holding}`
|
||||
const kenderaan_url = `https://drive.google.com/uc?export=view&id=${await id_kenderaan}`
|
||||
|
||||
console.log(new_kurir)
|
||||
|
||||
// await kurirModel.findOneAndUpdate({ _id: new_kurir._id }, {
|
||||
// status: 'Aktif',
|
||||
// photo_url: photo_url,
|
||||
// })
|
||||
|
||||
await kurirModel.findOneAndUpdate({ _id: new_kurir._id }, { photo_url: photo_url, ktp_url: ktp_url, ktp_holding_url: ktp_holding_url, kenderaan_url: kenderaan_url });
|
||||
|
||||
// const data = await kurirModel.findOne({ _id: new_kurir._id });
|
||||
|
||||
// console.log(data)
|
||||
|
||||
|
||||
let new_login = new loginUserModel(data);
|
||||
// let new_login = new loginUserModel(data);
|
||||
|
||||
// push new_kurir._id to new_login._idnya
|
||||
new_login._idnya = new_kurir._id;
|
||||
console.log(new_login);
|
||||
// // push new_kurir._id to new_login._idnya
|
||||
// new_login._idnya = new_kurir._id;
|
||||
// console.log(new_login);
|
||||
|
||||
await new_kurir.save();
|
||||
await new_login.save();
|
||||
// await new_kurir.save();
|
||||
// await new_login.save();
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,9 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
const {pengirimModel, kurirModel, loginUserModel} = require('../models/users_model');
|
||||
const { pengirimModel, kurirModel, loginUserModel } = require('../models/users_model');
|
||||
|
||||
const { pengaturanPengirimanModel } = require('../models/kurir_model');
|
||||
|
||||
|
||||
let googlenya = require('../google/googleapi.js');
|
||||
@ -35,15 +37,83 @@ router.get('/', cek_user_pengirim, async (req, res) => {
|
||||
})
|
||||
|
||||
// create '/pengirim' get route
|
||||
router.get('/kurir', cek_user_pengirim, async (req, res) => {
|
||||
// router.get('/kurir', cek_user_pengirim, async (req, res) => {
|
||||
router.get('/kurir', async (req, res) => {
|
||||
try {
|
||||
const data = await kurirModel.find({
|
||||
status: 'Aaaktif'
|
||||
}).select('-email -created_at -updated_at -__v -ktp_url -kenderaan_url -photo_url -_id -alamat');
|
||||
res.status(200).send({data : data});
|
||||
status: 'Aktif'
|
||||
}).select('-email -created_at -updated_at -__v -ktp_url -_id -alamat').populate(
|
||||
{
|
||||
path: 'pengaturan_pengiriman',
|
||||
}
|
||||
).exec();
|
||||
res.status(200).send({ data: data });
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: 'Internal Server Error' });
|
||||
}
|
||||
})
|
||||
|
||||
// create '/pengirim/:nama' get route
|
||||
router.get('/kurir/nama', cek_user_pengirim, async (req, res) => {
|
||||
try {
|
||||
const nama = (req.query.nama != null && req.query.nama != '') ? req.query.nama.toString() : '';
|
||||
const data = await kurirModel.find({
|
||||
nama: {
|
||||
$regex: nama,
|
||||
$options: 'i'
|
||||
}
|
||||
}).select('-email -created_at -updated_at -__v -ktp_url -_id -alamat').populate(
|
||||
{
|
||||
path: 'pengaturan_pengiriman',
|
||||
|
||||
}
|
||||
)
|
||||
res.status(200).send({ data: data });
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: 'Internal Server Error' });
|
||||
}
|
||||
})
|
||||
|
||||
// create '/pengirim/filter/' get route
|
||||
router.get('/kurir/filter/', cek_user_pengirim, async (req, res) => {
|
||||
|
||||
const nama = (req.query.nama != null && req.query.nama != '') ? req.query.nama.toString() : '';
|
||||
const biaya_maksimal = (req.query.biaya_maksimal != null && req.query.biaya_maksimal != '') ? parseInt(req.query.biaya_maksimal.toString()) : '';
|
||||
const biaya_per_kilo = (req.query.biaya_per_km != null && req.query.biaya_per_km != '') ? parseInt(req.query.biaya_per_km.toString()) : '';
|
||||
|
||||
const data = await pengaturanPengirimanModel.find(
|
||||
(biaya_per_kilo != '' && biaya_maksimal != '') ? {
|
||||
biaya_per_kilo: {
|
||||
$lte: biaya_per_kilo
|
||||
},
|
||||
biaya_maksimal: {
|
||||
$lte: biaya_maksimal
|
||||
}
|
||||
} :
|
||||
(biaya_per_kilo != '' && biaya_maksimal == '') ? {
|
||||
biaya_per_kilo: {
|
||||
$lte: biaya_per_kilo
|
||||
}
|
||||
} :
|
||||
(biaya_per_kilo == '' && biaya_maksimal != '') ? {
|
||||
biaya_maksimal: {
|
||||
$lte: biaya_maksimal
|
||||
}
|
||||
} : {}
|
||||
).populate({
|
||||
path: 'kurir',
|
||||
select: '-email -created_at -updated_at -__v -ktp_url -_id -alamat',
|
||||
match: {
|
||||
nama: {
|
||||
$regex: nama,
|
||||
$options: 'i'
|
||||
}
|
||||
}
|
||||
}).exec();
|
||||
console.log(data)
|
||||
|
||||
res.status(200).send({ data: data });
|
||||
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user