Skip to content

Commit

Permalink
transit node add and added several user types
Browse files Browse the repository at this point in the history
  • Loading branch information
polroti committed Mar 10, 2024
1 parent a2b987a commit 608e3f5
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 57 deletions.
29 changes: 19 additions & 10 deletions components/places/controller/transitNodeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const mongoose = require("mongoose");
const TransiteNode = require("../models/transitnode");

exports.createTransiteNode = (req, res, next) => {
const { name_en, name_ta, name_si, type, address, isStartOrEndNode } =
const { name_en, name_ta, name_si, type, address, isStartOrEndNode, province } =
req.body;

const newTransitNode = new TransiteNode({
Expand All @@ -14,6 +14,7 @@ exports.createTransiteNode = (req, res, next) => {
type: type,
address: address,
isStartOrEndNode: isStartOrEndNode,
province: province
});

newTransitNode.save().then((savedTransitNode) => {
Expand All @@ -33,7 +34,7 @@ exports.checkIfTransitNodeExistsByNameEn = (req, res, next) => {
.then((foundTrNode) => {
if (foundTrNode) {
res.status(409).json({
error: "Transit Node already exists",
error: "Transit Node already exists by name",
code: "TRANSIT_NODE_EXISTS",
});
} else {
Expand All @@ -43,15 +44,22 @@ exports.checkIfTransitNodeExistsByNameEn = (req, res, next) => {
};

exports.generatePlaceId = (req, res, next) => {
const randomChars = name_en
.split("")
.sort(() => 0.5 - Math.random())
.slice(0, 3)
.join("");
const timestamp = Date.now().toString(36); // Convert current timestamp to base36 string
const id = randomChars + timestamp; // Combine random characters and timestamp
// Remove spaces and convert to uppercase
inputStr = req.body.name_en.replace(/\s/g, "").toUpperCase();

// Take the first three characters of the input string
const firstThreeChars = inputStr.substring(0, 3);

// Count the number of characters in the input string
const numChars = inputStr.length;

// Generate the numeric part of the ID with leading zeros
const randomNumericPart = Math.floor(Math.random() * 100000).toString().padStart(5, '0');

// Concatenate the prefix, first three characters, and numeric part
const generatedId = req.body.province + firstThreeChars + randomNumericPart;

req.place_id = id.slice(0, 10);
req.place_id = generatedId.toUpperCase() + "454545454";

next();
};
Expand All @@ -63,6 +71,7 @@ exports.checkIfTransitNodeExistsByPlaceId = (req, res, next) => {
.exec()
.then((foundTrNode) => {
if (foundTrNode) {
console.log(req.place_id);
res.status(409).json({
error: "Transit Node already exists",
code: "TRANSIT_NODE_EXISTS",
Expand Down
2 changes: 2 additions & 0 deletions components/places/routes/transitNodeRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const routes = express.Router();

const tNodeController = require('../controller/transitNodeController')

//working ok - must check access
routes.post('/add',
tNodeController.checkIfTransitNodeExistsByNameEn,
tNodeController.generatePlaceId,
tNodeController.checkIfTransitNodeExistsByPlaceId,
tNodeController.createTransiteNode);
Expand Down
26 changes: 26 additions & 0 deletions components/user/entities/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mongoose = require("mongoose");

const adminUserSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
fullname: {
type: String,
required: true,
unique: true,
},
email: {
type: String,
required: true,
unique: true
},
phone:{
type: String,
required: true,
},
isActive:{
type: Boolean,
required: true,
default: true
}
})

module.exports = mongoose.model("AdminUser", adminUserSchema);
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
21 changes: 0 additions & 21 deletions components/user/entities/facebookUser.js

This file was deleted.

21 changes: 0 additions & 21 deletions components/user/entities/googleUser.js

This file was deleted.

11 changes: 6 additions & 5 deletions components/user/entities/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const userSchema = new mongoose.Schema({
required: true,
unique: true,
},
fullname: {
password: {
type: String,
required: true,
},
password: {
usertype:{
type: String,
required: true,
},
});

enum:['ADMIN','PASSENGER','DRIVER','CONDUCTOR','CHECKER','AUDITOR','PARTNER','EMPLOYEE']
}
})

module.exports = mongoose.model("User", userSchema);
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PORT = 5000 || process.env.PORT;
const secrets = require("./secrets.json");

const dbName = "sltb_api_db";
sltbApi.use(express.json());

//Define Routes
const bookingRoute = require("./components/booking/BookingRoutes");
Expand Down

0 comments on commit 608e3f5

Please sign in to comment.