Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
node-js-60-2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patiphan Marak
node-js-60-2
Commits
694e7b9c
Commit
694e7b9c
authored
Feb 07, 2018
by
Patiphan Marak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
give me point pls
parent
621cfa4b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
6 deletions
+88
-6
index.js
week04/contact-manager/index.js
+31
-3
logic.js
week04/contact-manager/logic.js
+48
-3
contact-manager
week04/contact-manager/node_modules/contact-manager
+2
-0
package.json
week04/contact-manager/package.json
+2
-0
use
week04/contact-manager/use
+5
-0
No files found.
week04/contact-manager/index.js
View file @
694e7b9c
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
week04/contact-manager/logic.js
View file @
694e7b9c
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
};
week04/contact-manager/node_modules/contact-manager
0 → 120000
View file @
694e7b9c
..
\ No newline at end of file
week04/contact-manager/package.json
View file @
694e7b9c
...
@@ -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"
,
...
...
week04/contact-manager/use
0 → 100644
View file @
694e7b9c
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment