const nodemailer = require("nodemailer"); router.sendMail = (req, res) => { const stmpconfig = { host: "smtpAddress", port: "465", secure: true, auth: { user: "abc@def.com", pass: "123456" } }; const from = "발신자명 < abc@def.com >"; const to = "수신자 이메일 주소"; const subject = "제목"; const html = "<p>내용</p>"; let mailOptions = { from, to, subject, html }; const transporter = nodemailer.createTransport(stmpconfig); transporter.verify((err, success) => { if (err) console.error(err); console.log("Your config is correct / " + success); }); transporter.sendMail(mailOptions, function(err, res) { if (err) { console.error("🤕 NodeMailer test failed with error:\n", err); } else { console.log("this is a new password: " + password); console.log("📬 Successfully sent NodeMailer test with result:\n", res); } }); transporter.close; res.send("it's over"); };


router.updateQA = (req, res) => {
    const data = (req.method == 'POST') ? req.body : req.query;
    const id = req.query._id;
    const fields = 'name, profile.qa'
    UserData.model
        .findById(id)
        .exec((err, user) => {
            if (err) return res.apiError(err);
            if (!user) return res.apiResponse({ message: "no user" });
            user.getUpdateHandler(req).process(
                data,
                { 
                    flashErrors: true, 
                    fields: fields,
                    errorMessage: 'error!!'
                },
                err => {
                    if (err) return res.apiError("error", err);
                    res.apiResponse({
                        status: "success",
                        result: user
                    });
                }
            );
        })
}

https://keystonejs.com/api/list/update-item/

fields: String|Array

A list of fields to attempt to update. All other fields will not be updated even if values are provided. 
If a string is passed, it will attempt to use list-to-array to transform the string.

즉 fields 에 주어진 필드들 외에 필드들은 값이 주어지더라도 업데이트 안함. 그리고 주어진 필드중의 필드를 업데이트 하지 않아도 상관없음.
그러나 업데이트 할 Document 의 필드 속성중 Relationship Type 필드들은 업데이트시 값을 주지 않으면 값이 날라감. 그외 필드들은 영향 없음
그래서 RelationshipType이 들어가는 Document 업데이트는 무조건 사용해야할듯



Ex)
-User Model

User.add({
    ... ,
	password: { type: Types.Password, initial: true, required: true },
	name: { type: Types.Name },
	birthday: { type: Types.Date, index: true, default: Date.now },
	gender: { type: Types.Select, options: 'M, W', default: 'M' },
	nationality: { type: Types.Relationship, ref: 'Nationality', initial: true },
    ...
})

let fields = 'password, name, gender, birthday';
if (data.nationality) fields += ', nationality';

password, name, gender, birthday 필드들은 relationship 타입이 아니라 값을 넣어도 되고 안넣어도 됨.
하지만 relationship 타입인 nationality 가 fields 에 들어있고 api 날릴때 key, value 값이 주어지지 않으면 null 값이 들어가 원래 값이 날라감.
그래서 User update 할 때 data 에 nationality 키가 포함 되어있으면 fields 에 포함시키고 아니면 포함 안 시킴.


'IT > KeystonJS' 카테고리의 다른 글

nodemailer 로 메일 보내기 + Keystonejs  (0) 2018.12.28
Keystone + Next js Routing 설정  (0) 2018.12.10
Keystonejs + Nextjs Production mode 설정  (0) 2018.12.05

1. 해당 EC2의 security group 에서 inbound 포트를 mongodb 포트로 열어준다


2. mongodb 를 실행중이라면


> sudo service mongod stop


으로 정지 시킨다


(간혹 위 명령어가 안 먹힐때가 있는데 그때는 


> cd /run/mongodb 로 해당 폴더로 이동하여


> ls 를 입력하면 mongod.pid 파일이 존재한다. 이유는 ec2 로컬에서 이미 mongod 로 서비스 중이라 그렇다.


우리는 sudo service mongod 를 사용할 예정이므로


> sudo rm -rf mongod.pid 로 해당 파일을 삭제한다)


3. 정지 시킨뒤 sudo vi /etc/mongod.conf 로 conf 파일을 아래와 같이 수정한다




bindIp 앞의 #을 지워주고 bindIp 를 위와 같이 0.0.0.0 으로 바꿔준다


원래 127.0.0.1 로 되어있는데 이건 해당 ec2 로컬에서만 접속가능하게 하기 위해서 이므로 bindIp 변경이 필수다.


혹시나 

해당 부분에 #이 안되어 있으면 #을 꼭 해줘야 본인 컴퓨터 로컬에서 접속이 가능하다


4. conf 파일을 저장하고 (혹시나 모른다면 esc -> wq -> enter 로 변경사항 저장후 나가기 이다)


> sudo service mongod restart 로 mongodb 를 재시작 해준다.


5. 로컬 컴퓨터에서 compass 를 켠다.


Hostname : elasticip

Port : mongodb port


그리고 connect 를 하면 접속 성공


6. 혹시나 그래도 compass 에서 접속시 에러가 나서 접속이 불가능 하다면 ec2 로컬에서 

> mongo 

로 db에 접속하여 admin 이나 root 계정을 만들어준다



+ Recent posts