Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
nodejs_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
Piyunggur Sonsongklin
nodejs_60_2
Commits
c81fd385
Commit
c81fd385
authored
Feb 07, 2018
by
Littichai Buddaken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path 4
parent
76e2ea28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
47 deletions
+55
-47
index.js
week04/contact-manager/index.js
+21
-22
logic.js
week04/contact-manager/logic.js
+34
-25
No files found.
week04/contact-manager/index.js
View file @
c81fd385
#!/usr/bin/env node
//const lower = require("./logic"); // impport function
const
{
addContact
,
getContact
}
=
require
(
"./logic"
);
// const lower = require("./logic") //require with .file name
//console.log(lower.toLower("PATIPHAN MARAK"));
// console.log(lower.toLower('mai mai'))
const
program
=
require
(
'commander'
);
const
program
=
require
(
'commander'
);
program
program
.
version
(
'0.1.0'
)
.
version
(
'0.1.0'
)
.
description
(
'Contact management system'
);
.
description
(
'Contact management system'
);
progarm
.
command
(
'programmer'
)
.
alias
(
'p'
)
.
description
(
'ดูข้อมูลของโปรแกรมเมอร์'
)
.
action
(()
=>
{
console
.
log
(
'programmer คือ ไม้'
);
});
program
program
.
command
(
'addContact <fame> <lname> <phone> <email>'
)
.
command
(
'addContact <firstame> <lastname> <phone> <email>'
)
.
alias
(
'a'
)
.
alias
(
'a'
)
.
description
(
'Add a contact'
)
.
description
(
'Add a contact'
)
.
action
((
fname
,
lname
,
phone
,
email
)
=>
{
.
action
((
firstname
,
lastname
,
phone
,
email
)
=>
{
//addContact({firstname, lastname, phone, email});
//addContact({ firstname, lastname, phone, email });
//console.log('User wants to addContact');
console
.
log
(
`User :
${
firstname
}
${
lastname
}
${
phone
}
${
email
}
`
);
//addContact({firstname, lastname, phone, email});
});
addContact
(
`User:
${
fname
}
${
lname
}
${
phone
}
${
email
}
`
);
});
program
.
command
(
'programmer'
)
.
alias
(
'p'
)
.
description
(
'programmer'
)
.
action
(()
=>
{
console
.
log
(
Programmer
is
Piyunggur
);
});
console
.
log
(
process
.
argv
);
console
.
log
(
process
.
argv
);
//program.parse(process.argv)
//program.parse(process.argv)
; // พาสคำสั่ง
week04/contact-manager/logic.js
View file @
c81fd385
function
toLower
(
v
){
function
toLower
(
v
)
{
return
v
.
toLowerCase
();
return
v
.
toLowerCase
();
}
};
const
mongoose
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
// const assert = require('assert');
// const assert = require('assert');
mongoose
.
Promise
=
global
.
Promise
;
// Promise
mongoose
.
Promise
=
global
.
Promise
;
const
db
=
mongoose
.
connect
(
'mongodb://localhost:27017/contactdb'
);
const
db
=
mongoose
.
connect
(
'mongodb://localhost:27017/contactdb'
);
const
contactSchema
=
mongoose
.
Schema
({
const
contactSchema
=
mongoose
.
Schema
({
fname
:
{
type
:
String
,
set
:
toLower
},
firstname
:
{
lname
:
{
type
:
String
,
set
:
toLower
},
type
:
String
,
phone
:
{
type
:
String
,
set
:
toLower
},
set
:
toLower
email
:
{
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
Contact
=
mongoose
.
model
(
'Contact'
,
contactSchema
);
const
addContact
=
(
contact
)
=>
{
const
addContact
=
(
contact
)
=>
{
console
.
info
(
`กำลังเพิ่มรายการติดต่อ
${
contact
}
`
);
Contact
.
create
(
contact
,
(
err
)
=>
{
Contact
.
create
(
contact
,
(
err
)
=>
{
console
.
info
(
'New contact added'
);
console
.
info
(
'เพิ่มรายการติดต่อใหม่สำเร็จ'
);
db
.
disconnect
();
db
.
disconnect
();
});
});
};
};
const
getContact
=
(
name
)
=>
{
const
getContact
=
(
name
)
=>
{
// Define search criteria. The search here is case-insensitive and inexact.
const
search
=
new
RegExp
(
name
,
'i'
);
const
search
=
new
RegExp
(
name
,
'i'
);
Contact
.
find
({
$or
:
[{
firstname
:
search
},
{
lastname
:
search
}]
})
Contact
.
find
({
$or
:
[{
fname
:
search
},
{
lname
:
search
}]})
.
exec
((
err
,
contact
)
=>
{
.
exec
((
err
,
contact
)
=>
{
console
.
info
(
contact
);
console
.
info
(
contact
);
console
.
info
(
ค้นเจอทั้งหมด
$
{
contact
.
length
}
รายการ
);
console
.
info
(
`ค้นเจอทั้งหมด
${
contact
.
length
}
รายการ`
);
db
.
disconnect
();
db
.
disconnect
();
});
});
};
};
module
.
exports
=
{
addContact
,
getContact
}
;
// exports.toLower = lower
;
// exports .toLower = lower // exports , all file can user it
module
.
exports
=
{
addContact
,
getContact
};
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