Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up send email #9

Merged
merged 1 commit into from
Jan 15, 2022
Merged

Conversation

kkinggmann
Copy link
Collaborator

No description provided.

@kkinggmann kkinggmann force-pushed the set_up_send_email branch 6 times, most recently from c3b7caa to f91a815 Compare January 14, 2022 10:26
@kkinggmann
Copy link
Collaborator Author

@sagara11 @SalamanderHP pls review my pr

@kkinggmann
Copy link
Collaborator Author

@sagara11 @SalamanderHP pls check the pr

@@ -24,3 +24,4 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
src/contracts/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann cái yarn này t bỏ ở pr t rồi mà, check lại xem bị thừa ko

@@ -46,4 +49,22 @@ User.statics.findByAddress = async function (publicAddress) {
return user;
};

User.pre("findOneAndUpdate", async function (next) {
Copy link
Collaborator

@SalamanderHP SalamanderHP Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann hàm findOneAndUpdate là hàm có sẵn rồi giờ m lại định nghĩa 1 hàm riêng của model làm gì, trong service có thể dùng nhiều hàm mặc định của model tùy úy chứ t nghĩ ko nên định nghĩa lại quá nhiều mấy hàm đơn giản vào model này

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SalamanderHP k phải, cái này là callback thôi. Là trước khi findOneAndUpdate thì nó chạy. Giống mấy cái callback trong rails ý

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann ừ ko để ý cái pre, chỗ logic kia đưa vào 1 service nhé đừng viết kiểu next trong model

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service cũng không nên đưa next vào, luồng request thì ở controller hết nhé

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SalamanderHP cái trong callback thì nếu dùng là cần viết next() đấy, để nó chạy được tiếp khi qua callback. Cơ mà chắc chỗ này không cần callback đâu

// Check only send email after fill second step form
if (isEmpty(preUpdatedUser.email) && !isEmpty(this.getUpdate().$set.email)) {
const email = this.getUpdate().$set.email;
sendEmailJob(email, `New email: ${email}`, "New account");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann model thì không có logic nhé, tất cả những chỗ logic này nên ở service chứ không ở model

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SalamanderHP oke để nghĩ lại chỗ này đưa vào service

@@ -14,6 +14,17 @@ const addNewUser = async (publicAddress) => {
return user;
};

const updateUser = async (publicAddress, data) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann nên viết 1 đối tượng const userService rồi bên trong nó là các function, ở controller sẽ dễ đọc hơn

Comment on lines 28 to 40
addNewUser,
updateUser,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann viết thế kia thì chỉ việc export cái userService đó là bên controller sẽ implement như sau: userService.updateUser -> debug sẽ dễ tìm được hàm này thuộc service nào

@@ -18,5 +18,5 @@ export function signupAPI(params) {
}

export function updateAccountAPI(params) {
return axios.put(`${URL}/users/update`, params, config);
return axios.put(`${URL}/users/update/${params.publicAddress}`, params.data, config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann cần gì phải có chữ update khi đã sử dụng phương thức put nhỉ

@kkinggmann kkinggmann force-pushed the set_up_send_email branch 3 times, most recently from ea5cdf8 to 49e26ca Compare January 15, 2022 09:15
@kkinggmann
Copy link
Collaborator Author

@SalamanderHP @sagara11 pls review

Comment on lines +17 to +18
const {publicAddress} = req.params;
const data = req.body;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann trong phạm vi hàm để truyền vào update thì dùng let cũng được ko cần const, mà để thế cũng đc k cần fix

const {publicAddress} = req.params;
const data = req.body;

const updatedUser = await UserServices.updateUser(publicAddress, data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkinggmann service này nên để camelCase thôi object mà, thống nhất về sau nữa, fix cái này thôi còn đâu code quá clean rồi

@SalamanderHP SalamanderHP merged commit b145492 into sagara11:main Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants