-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
582 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const { User } = require("../models/User"); | ||
const bcrypt = require("bcrypt"); | ||
|
||
var createAdmin = async () => { | ||
const users = new User({ | ||
name: "adminPerpus", | ||
email: "[email protected]", | ||
password: "perpussmkn21", | ||
category: "ADMIN", | ||
productKey: "PerpusKuKeren" | ||
}); | ||
|
||
const salt = await bcrypt.genSalt(10); | ||
users.password = await bcrypt.hash(users.password, salt); | ||
|
||
await users.save(); | ||
console.log("Akun admin berhasil dibuat"); | ||
}; | ||
|
||
module.exports = createAdmin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
const mongoose = require("mongoose"); | ||
const db = "mongodb+srv://perpusku:[email protected]/?retryWrites=true&w=majority" | ||
|
||
const connectDB = async () => { | ||
try { | ||
await mongoose.connect(db, { | ||
useNewUrlParser: true, | ||
useCreateIndex: true, | ||
useFindAndModify: false, | ||
useUnifiedTopology: true | ||
}); | ||
console.log("> MongoDB Connected..."); | ||
} catch (err) { | ||
console.log("> Connection to MongoDB failed..."); | ||
console.error(err.message); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
module.exports = connectDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const jwt = require("jsonwebtoken"); | ||
const jwtSecret = "PerpusKuKeren" | ||
|
||
module.exports = function (req, res, next) { | ||
const token = req.header("x-auth-token"); | ||
|
||
if (!token) { | ||
return res.status(401).json({ msg: "No token, authorization denied." }); | ||
} | ||
|
||
try { | ||
const decoded = jwt.verify(token, jwtSecret); | ||
req.user = decoded.user; | ||
next(); | ||
} catch (err) { | ||
res.status(401).json({ msg: "Token is not valid." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const BookCategorySchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("bookcategory", BookCategorySchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const BooksSchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
publisher: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "publisher" | ||
}, | ||
bookcategory: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "bookcategory" | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
author: { | ||
type: String, | ||
required: true | ||
}, | ||
publicyear: { | ||
type: Number, | ||
required: true | ||
}, | ||
isbn: { | ||
type: Number, | ||
required: true | ||
}, | ||
goodbooks: { | ||
type: Number, | ||
required: true | ||
}, | ||
damagedbooks: { | ||
type: Number, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("books", BooksSchema); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const GroupSchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
abrev: { | ||
type: String, | ||
required: true | ||
}, | ||
desc: { type: String }, | ||
color: { type: String, default: "yellow" }, | ||
students: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "student" | ||
} | ||
], | ||
courses: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "course" | ||
} | ||
], | ||
exams: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "exam" | ||
} | ||
], | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
}, | ||
}); | ||
|
||
module.exports = mongoose.model("group", GroupSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const PublisherSchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
status: { | ||
type: String, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("publisher", PublisherSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const SchoolSchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
logo: { | ||
fileName: { type: String }, | ||
filePath: { type: String } | ||
}, | ||
name: { | ||
type: String, | ||
required: true | ||
}, | ||
abrev: { type: String }, | ||
desc: { type: String }, | ||
period: { type: String }, | ||
address: { type: String }, | ||
email: { type: String }, | ||
phone1: { type: String }, | ||
phone2: { type: String }, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("school", SchoolSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @author CodeArch_Indonesia <[email protected]> | ||
* @license MIT | ||
* @app PerpusKu | ||
*/ | ||
|
||
|
||
const mongoose = require("mongoose"); | ||
|
||
const StudentSchema = mongoose.Schema({ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "users" | ||
}, | ||
group: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "group" | ||
}, | ||
nameFirst: { | ||
type: String, | ||
required: true | ||
}, | ||
nameLast: { | ||
type: String, | ||
required: true | ||
}, | ||
code: { | ||
type: Number, | ||
required: true | ||
}, | ||
date: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model("student", StudentSchema); |
Oops, something went wrong.