Skip to content

Namhv #16

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bai2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express')
const MathServiceClient = require('./goi2.js')
const app = express()
const port = 3000

app.use(express.json());

app.post('/api/register', async (req, res) => {
console.log(req.body);
const mathServiceClient = new MathServiceClient();
const result = await mathServiceClient.sum({
first_name: req.body.first_name,
last_name: req.body.last_name,
password: req.body.password,
password_confirmation: req.body.password_confirmation,
email: req.body.email
})
res.send({result});
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
30 changes: 30 additions & 0 deletions code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function insochan() {
console.log("in số chẵn:")
for (let i = 0; i <= 10; i += 2) {
console.log(i);
}
}

function bangcuutruong() {
console.log("bảng cửu trương:")
for (let i = 0; i <= 10; i++) {
for (let j = 0; j <= 10; j++) {
console.log(i,"x", j,"=",i*j)
}
}
}
function tong3so() {
var c;
console.log("tong 3 so có tổng bằng 10 là:")
for (let a = 0; a <= 10; a++) {
for (let b = 0; b <= 10; b++) {
if (a + b <= 10 && 0 <= a + b) {
c = 10 - a - b;

console.log(a, b, c);
}
}
}
}

module.exports = { tong3so, bangcuutruong, insochan }
17 changes: 17 additions & 0 deletions goi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const axios = require('axios');
function MathServiceClient() {
this.baseURL = process.env.MATH_SERVICE_URL || 'http://localhost:4000';
}

MathServiceClient.prototype.sum = async function (data) {
const config = {
url: `${this.baseURL}/api/sum`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data
};
const response = await axios(config);
return response.data;
};

module.exports = MathServiceClient;
17 changes: 17 additions & 0 deletions goi2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const axios = require('axios');
function MathServiceClient() {
this.baseURL = process.env.MATH_SERVICE_URL || 'http://localhost:4000';
}

MathServiceClient.prototype.sum = async function (data) {
const config = {
url: `${this.baseURL}/api/users/register`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data
};
const response = await axios(config);
return response.data;
};

module.exports = MathServiceClient;
26 changes: 26 additions & 0 deletions kiemtra.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const express = require('express');
const validateUser = require('./testjoi.js');
const app = express();
const port = 4000;
app.use(express.json());
app.post('/api/users/register', (req, res) => {
console.log(req.body)
const { error } = validateUser(req.body);
if (error) {
return res.status(400).send(error.details[0].message);
}
// Nếu hợp lệ, tiếp tục xử lý
// const user = {
// first_name: req.body.first_name,
// last_name: req.body.last_name,
// password: req.body.password,
// email: req.body.email
// };
// res.send(user);
res.json({ result: "đăng ký thành công"})
});


app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const{tong3so, insochan, bangcuutruong}=require('./code.js')

// import { tong3so } from './code.js';

tong3so();
insochan();
bangcuutruong();
Loading