Commit 694e7b9c authored by Patiphan Marak's avatar Patiphan Marak

give me point pls

parent 621cfa4b
const lower = require("./logic") #!/usr/bin/env node
//const lower = require("./logic"); // impport function
const {addContact, getContact} = require("./logic");
console.log(lower.toLower("PATIPHAN MARAK")) //console.log(lower.toLower("PATIPHAN MARAK"));
\ No newline at end of file
const program = require('commander');
program
.version('0.1.0')
.description('Contact management system');
program
.command('addContact <firstame> <lastname> <phone> <email>')
.alias('a')
.description('Add a contact')
.action((firstname, lastname, phone, email) => {
//addContact({ firstname, lastname, phone, email });
console.log(`User : ${firstname} ${lastname} ${phone} ${email} `);
});
program
.command('programmer')
.alias('p')
.description('programmer')
.action(() => {
console.log(`Programmer is Patiphan`);
});
console.log(process.argv);
//program.parse(process.argv); // พาสคำสั่ง
\ No newline at end of file
let lower = function toLower(v) { function toLower(v) {
return v.toLowerCase(); return v.toLowerCase();
} };
exports.toLower = lower
const mongoose = require('mongoose');
// const assert = require('assert');
mongoose.Promise = global.Promise;
const db = mongoose.connect('mongodb://localhost:27017/contactdb');
const contactSchema = mongoose.Schema({
firstname: {
type: String,
set: toLower
},
lastname: {
type: String,
set: toLower
},
phone: {
type: String,
set: toLower
},
email: {
type: String,
set: toLower
}
});
const Contact = mongoose.model('Contact', contactSchema);
const addContact = (contact) => {
Contact.create(contact, (err) => {
console.info('New contact added');
db.disconnect();
});
};
const getContact = (name) => {
const search = new RegExp(name, 'i');
Contact.find({ $or: [{ firstname: search }, { lastname: search }] })
.exec((err, contact) => {
console.info(contact);
console.info(`ค้นเจอทั้งหมด ${contact.length} รายการ`);
db.disconnect();
});
};
// exports.toLower = lower;
module.exports = { addContact, getContact };
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
"main": "index.js", "main": "index.js",
"author": "Patiphan", "author": "Patiphan",
"license": "MIT", "license": "MIT",
"preferGlobal": true,
"bin": "./index.js",
"dependencies": { "dependencies": {
"commander": "^2.14.0", "commander": "^2.14.0",
"inquirer": "^5.1.0", "inquirer": "^5.1.0",
......
MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017/-
MongoDB server version: 3.6.2
2018-02-07T21:45:05.859+0700 E - [main] file [contactdb] doesn't exist
failed to load: contactdb
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