I'M_DEVELOPERπŸ‘¨β€πŸ’»
15 subscribers
12 photos
3 videos
1 link
HELLOπŸ™‹β€β™‚οΈ , Welcome to my channel πŸ’«
I AM BACKEND NODE JS DEVELOPER πŸ‘¨β€πŸ’»
Download Telegram
const express = require("express");
const cors = require("cors");
const {
userCreateSchema,
userPatchSchema,
userPutSchema,
} = require("./scheams");

const app = express();

app.use(cors());
app.use(express.json());

const users = [
{
id: 1,
login: "admin",
password: "admin",
fullName: "admin",
},
{
id: 2,
login: "admin1",
password: "admin",
fullName: "Admin Ok",
},
];

function getById(id) {
const foundUser = users.findIndex((el) => el.id === id);

if (foundUser === -1) {
return undefined;
} else {
return foundUser;
}
}

// user listni get qilish

app.get("/api/users", (req, res) => {
res.json({ stausCode: 200, message: "ok", data: users });
});

// post create qilish

app.post("/api/users", (req, res) => {
const dto = req.body;

const { error } = userCreateSchema.validate(dto);

if (error) {
return res.status(400).json({ stausCode: 400, message: error.message });
}

const newUser = {
id: users[users.length - 1].id + 1,
login: dto.login,
password: dto.password,
fullName: dto.fullName,
};

users.push(newUser);

res.status(201).json({ stausCode: 201, message: "created", data: newUser });
});

// delete berilgan id dagi ma'lumotni o'chirish

app.delete("/api/users/:id", (req, res) => {
let id = req.params.id;

id = Number(id);

if (isNaN(id)) {
return res.status(400).json({ statusCode: 400, message: "Invalid id" });
}

const userIndex = getById(id);

if (typeof userIndex === "undefined") {
return res.status(404).json({ statusCode: 404, message: "user not found" });
}

const deleteUser = users.splice(userIndex, 1);

res
.status(200)
.json({ statusCode: 200, message: "deleted", data: deleteUser });
});

// getById id berilsa o'sha id dagi ma'lumotni olib kelib berishi kerak

app.get("/api/user/:id", (req, res) => {
let id = req.params.id;

id = Number(id);

if (isNaN(id)) {
return res.status(400).json({ statusCode: 400, message: "Invalid id" });
}

const userIndex = getById(id);

if (typeof userIndex === "undefined") {
return res.status(404).json({ statusCode: 404, message: "user not found" });
}
res.status(200).json({
data: users[userIndex],
});
});

// patch metodi fullName ni o'zgartirish uchun ishlatiladi

app.patch("/api/user/:id", (req, res) => {
const dto = req.body;

const { error } = userPatchSchema.validate(dto);

if (error) {
return res.status(400).json({ stausCode: 400, message: error.message });
}

let id = req.params.id;

id = Number(id);

if (isNaN(id)) {
return res.status(400).json({ statusCode: 400, message: "Invalid id" });
}

const userIndex = getById(id);

if (typeof userIndex === "undefined") {
return res.status(404).json({ statusCode: 404, message: "user not found" });
}

users[userIndex].fullName = dto.fullName;
res.status(200).json({
statusCode: 200,
message: "fullName changed",
data: users[userIndex].fullName,
});
});

// put metodi hammasini yangilash (update qilish!)

app.put("/api/user/:id", (req, res) => {
const dto = req.body;

const { error } = userPutSchema.validate(dto);

if (error) {
return res.status(400).json({ stausCode: 400, message: error.message });
}

let id = req.params.id;

id = Number(id);

if (isNaN(id)) {
return res.status(400).json({ statusCode: 400, message: "Invalid id" });
}

const userIndex = getById(id);

if (typeof userIndex === "undefined") {
return res.status(404).json({ statusCode: 404, message: "user not found" });
}
function update() {
users[userIndex].fullName = dto.fullName;
users[userIndex].password = dto.password;
users[userIndex].login = dto.login;
}

res.status(200).json({
statusCode: 200,
message: "user updated",
data: update(),
});
});

app.listen(3000, () => {
console.log("Server is running on port 3000");
});
mayda fayllar qo'shilganda 600 qator kod bo'larkan πŸ’† ( sabr bersin😁)
πŸ”₯3πŸ‘Œ1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CHAT</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
background-color: #f9f9f9;
}
#messageDisplay {
width: 100%;
max-width: 500px;
margin-bottom: 20px;
padding: 10px;
background: #00eeff;
border: 1px solid #f60808;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow-y: auto;
max-height: 300px;
}
input {
width: 100%;
max-width: 492px;
height: 40px;
margin-bottom: 10px;
font-size: 16px;
border-radius: 5px;
background-color: rgb(255, 255, 255);
}
button {
text-align: center;
padding: 10px 20px;
font-size: 16px;
color: white;
background-color: #0ab919;
border: none;
border-radius: 5px;
cursor: pointer;
margin-bottom: 10px;
margin-left: 210px;
}
button:hover {
background-color: #185fab;
}
input {
font-size: 40px;
}
p {
text-align: center;
font-size: 20px;
font-style: italic;
border-radius: 10px;
margin-right: 120px;
margin-left: 80px;
margin-bottom: 10px;
padding: 0;
color: white;
background-color: rgb(31, 100, 149);
}
input::placeholder {
font-style: italic;
font-size: 40px;
}
li {
margin: 0px;
font-size: 30px;
background-color: rgb(251, 251, 243);
font-style: italic;
}
select {
margin-left: 100px;
color: rgb(21, 83, 119);
background-color: rgb(67, 238, 15);
border-radius: 5px;
}
</style>
</head>
<body>
<div id="messageDisplay">
<ul id="messages">
<select id="select"></select>
<p>THIS IS MY STILEπŸ—Ώ</p>
</ul>
<input
id="messageInput"
autocomplete="on"
placeholder="Type your message..."
/>
<button id="sendButton">SEND</button>
</div>
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
<script src="./main.js"></script>
</body>
</html>
πŸ”₯3πŸ‘Œ1
const socket = io("http://localhost:7777");

const messageDisplay = document.getElementById("messages");
const sendButton = document.getElementById("sendButton");
const messageInput = document.getElementById("messageInput");
const select = document.getElementById("select");

socket.on("onlineUsers", ({ data }) => {
select.innerHTML = "";
data.forEach((onlineUser, index) => {
const option = document.createElement("option");
option.value = onlineUser;
option.textContent = index + 1 + " ) " + onlineUser;
select.appendChild(option);
});
});

socket.on("message", ({ data }) => {
const p = document.createElement("p");
p.textContent = data.message;
messageDisplay.appendChild(p);
});

sendButton.addEventListener("click", () => {
const message = messageInput.value.trim();
if (message) {
socket.emit("send", { message });
messageInput.value = "";
}
});
πŸ”₯2πŸ‘Œ2πŸ₯°1
const { v4: uuidv4 } = require("uuid");
const express = require("express");
const cors = require("cors");
const http = require("http");
const socketIo = require("socket.io");

const app = express();
const server = http.createServer(app);
const io = socketIo(server, { cors: { origin: "*" } });

class ResData {
constructor(statusCode, message, data) {
this.statusCode = statusCode;
this.message = message;
this.data = data;
}
}

app.use(cors());
app.use(express.json());

const messages = [];
const onlineUsers = new Set();

io.on("connection", (socket) => {
console.log("user is connected:", socket.id);
onlineUsers.add(socket.id);

io.emit(
"onlineUsers",
new ResData(200, "online users updated", Array.from(onlineUsers))
);

socket.on("send", (data) => {
if (!data.message) {
return socket.emit("error", new ResData(400, "message is not defined"));
}

const newMessage = {
id: uuidv4(),
senderId: socket.id,
message: data.message,
};

messages.push(newMessage);

socket.broadcast.emit(
"message",
new ResData(200, "new message received", newMessage)
);
});

socket.on("disconnect", () => {
console.log("user is disconnected:", socket.id);
onlineUsers.delete(socket.id);

io.emit(
"onlineUsers",
new ResData(200, "online users updated", Array.from(onlineUsers))
);
});
});

// get metodi
app.get("/messages", (req, res) => {
res.json(new ResData(200, "All messages", messages));
});

// post metodi
app.post("/messages", (req, res) => {
const { message } = req.body;

if (!message) {
return res.status(400).json(new ResData(400, "must be a message"));
}

const newMessage = {
id: uuidv4(),
senderId: "server",
message,
};

messages.push(newMessage);

io.emit("message", new ResData(200, "new message added", newMessage));

res
.status(201)
.json(new ResData(201, "message created successfully", newMessage));
});

// put metodi
app.put("/messages/:id", (req, res) => {
const { id } = req.params;
const { message } = req.body;

const index = messages.findIndex((msg) => msg.id === id);

if (index === -1) {
return res.status(404).json(new ResData(404, "message is not defined"));
}

messages[index].message = message;

io.emit(
"messageUpdated",
new ResData(200, "message updated", messages[index])
);

res.json(new ResData(200, "message updated successfully", messages[index]));
});

// delete metodi
app.delete("/messages/:id", (req, res) => {
const { id } = req.params;

const index = messages.findIndex((msg) => msg.id === id);

if (index === -1) {
return res.status(404).json(new ResData(404, "message is not defined"));
}

const deletedMessage = messages.splice(index, 1);

io.emit(
"messageDeleted",
new ResData(200, "message deleted", deletedMessage[0])
);

res.json(new ResData(200, "message deleted successfully", deletedMessage[0]));
});

server.listen(7777, () => {
console.log("http://localhost:7777");
});
πŸ”₯7πŸ’˜1
Channel name was changed to Β«I'M_DEVELOPERπŸ‘¨β€πŸ’»Β»
-- Darsdagilar

create DATABASE ok;
--
create SCHEMA ok;
--
create TABLE users(
id serial primary key,
email varchar(255) not null unique,
password varchar(255) not null
);
--
create TABLE ok.users(
id serial primary key,
name varchar(255) not null,
email varchar(255) not null unique,
password varchar(255) not null
);

--
--

insert into users(email, password)
values ('no@gmail.com', 'test'),
('no2@gmail.com', 'test'),
('no3@gmail.com', 'test'),
('no4@gmail.com', 'test'),
('no5@gmail.com', 'test'),
('no6@gmail.com', 'test'),
('no7@gmail.com', 'test'),
('no8@gmail.com', 'test');

SELECT * FROM users;

--

insert into ok.users(email, password, birthday, is_marrige)
values ('no9@gmail.com', 'test', '2001-07-05', false),
('no@gmail.com', 'test', '2001-07-06', false),
('no2@gmail.com', 'test', '2001-07-07', true),
('no3@gmail.com', 'test', '2001-07-08', false),
('no4@gmail.com', 'test', '2001-07-09', true),
('no5@gmail.com', 'test', '2001-07-10', false),
('no6@gmail.com', 'test', '2001-07-11', true),
('no7@gmail.com', 'test', '2001-07-12', false),
('no8@gmail.com', 'test', '2001-07-02', true);

SELECT * FROM ok.users;

--

update ok.users set password='ok' where is_marrige=true;

--

select * from ok.users where full_name like '%n';
select * from ok.users where full_name ilike 'h%';

-- Uyga vazifa


create DATABASE hw1; -- database homework 6month 1 lesson

--

create SCHEMA schema_1;

--USERS

create table schema_1.users(
id serial primary key,
full_name varchar(64) default null,
email varchar(64) unique not null,
password text not null,
role varchar(64) default null );

--
--

insert into schema_1.users(full_name, email, password, role)
values ('Ziyodullo Najmiddinov', 'ziyodillo@gmail.com', '1234', 'admin'),
('Muhammadali Abdurasulov', 'ali@gmail.com', '1234', 'manager'),
('Ergashev Vasliddin', 'vasliddin@gmail.com', '2007', 'admin'),
('Abdurahmonov Ziyodullo', 'ziyodullo012@gmail.com', '1223', 'admin'),
('user1', 'user@gmail.com', '1223', 'manager');

SELECT * FROM schema_1.users;
where full_name between 'Ziyodullo Najmiddinov' and 'Abdurahmonov Ziyodullo'

update schema_1.users set role='leader' where email='user@gmail.com';

DELETE FROM schema_1.users WHERE role = 'leader';

select * from ok.users where full_name like '%Z';

select * from ok.users where full_name ilike '%N';


--
--

--TASKS

CREATE TABLE schema_1.tasks (
id SERIAL PRIMARY KEY,
title VARCHAR(64) DEFAULT NULL,
description VARCHAR(64) DEFAULT NULL,
start_date TIMESTAMP DEFAULT NOW(),
end_date TIMESTAMP DEFAULT NOW(),
status TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);

--
--

insert into schema_1.tasks(title, status,description)
values ('tayyor', 'created', 'new1'),
('tayyor2', 'created', 'new2'),
('tayyor3', 'created', 'new3'),
('tayyor4', 'created', 'new4');

SELECT * FROM schema_1.tasks;
where description between 'new1' and 'new4'

update schema_1.tasks set title='ok' where status='created';

DELETE FROM schema_1.tasks WHERE description = 'new1';

select * from schema_1.tasks where description like '%n';

select * from schema_1.tasks where description ilike '%3';

--
--

--NOTIFICATIONS

create table schema_1.notifications(
id serial primary key,
title varchar(64) default null,
message varchar(64) not null,
is_global boolean not null);

--
--

insert into schema_1.notifications(title, message,is_global)
values ('new', 'created', true),
('new2', 'ended', false),
('new3', 'inprogress', true),
('new4', 'created', false);

SELECT * FROM schema_1.notifications;
where title between 'ok' and 'ok';

update schema_1.tasks set title='ok' where message='created';

DELETE FROM schema_1.tasks WHERE title = 'new';

select * from schema_1.tasks where title like '%n';

select * from schema_1.tasks where title ilike '%4';

--
--

--MESSAGES

create table schema_1.messages(
id serial primary key,
message varchar(64) not null,
from_ varchar(64) default null,
to_ varchar(64) default null,
is_read boolean not null
);
πŸ”₯2❀1🀝1πŸ’˜1


--
--

insert into schema_1.messages(message, from_, to_, is_read)
values ('salom', 'you', 'I', true),
('salom2', 'user1', 'you', false),
('salom3', 'user2', 'I', true),
('salom4', 'you', 'he', false);

SELECT * FROM schema_1.messages;
where message between 'salom' and 'salom4';

update schema_1.messages set from_='I' where is_read=true;

DELETE FROM schema_1.messages where to_ = 'you';

select * from schema_1.messages where message like 's%';

select * from schema_1.messages where message ilike '%4';
--
πŸ”₯3🀝2πŸ‘1πŸ¦„1
create schema hw4;

create table hw4.cars (
id serial primary key,
model varchar(255) not null,
price int not null,
count int default 0
);

--
--

insert into hw4.cars(model,price,count) values
('BMW',10000,50),
('ROLLS ROYCE',20000,10),
('TOYOTA',8000,1000),
('MERCEDEZ',1000,40),
('SUPRA',12000,15);

select * from hw4.cars;

--user create

create table hw4.users(
id serial primary key,
fullname varchar(255),
balance int not null
);

insert into hw4.users(fullname,balance) values
('user1',100000),
('user2',200000),
('user3',80000),
('user4',10000),
('user5',120000);

-- first function...

create or replace function get_price_car(min_price int)
returns table(id int, model varchar(255), price int, count int)
language plpgsql
as
$$
begin
return query
select
c.id,
c.model,
c.price,
c.count from hw4.cars as c
where c.price > min_price order by price ASC;
end;
$$;

select * from get_price_car(8000);

-- second function...

create or replace function get_car_id(car_id int)
returns text
language plpgsql
as
$$
declare car_list text;
begin
select concat(
'id: ', c.id,
', model: ', c.model,
', price: ', c.price,
'. count: ', c.count)
into car_list
from hw4.cars as c
where c.id = car_id;
return car_list;
end;
$$;

select * from get_car_id(1);

--procedure

create or replace procedure buy_car(car_id int, car_count int, user_id int)
language plpgsql
as
$$
declare
car_price int;
car_count_available int;
user_balance int;
begin
select price, count into car_price, car_count_available
from hw4.cars
where id = car_id;

if car_price is null or car_count_available is null then
raise notice 'mashina topilmadi';
rollback;
return;
end if;

select balance into user_balance
from hw4.users
where id = user_id;

if user_balance is null then
raise notice 'foydalanuvchi topilmadi';
rollback;
return;
end if;

if user_balance < car_count * car_price then
raise notice 'foydalanuvchining balansida yetarli pul topilmadi';
rollback;
return;
end if;

if car_count_available < car_count then
raise notice 'mashinadan buncha emas';
rollback;
return;
end if;

update hw4.cars
set count = count - car_count
where id = car_id;

update hw4.users
set balance = balance - car_count * car_price
where id = user_id;

select balance into user_balance
from hw4.users
where id = user_id;

if user_balance < 5 then
raise notice 'foydalanuvchining balansida minimal summa 5 som dan kam';
rollback;
return;
end if;

commit;

raise notice 'buyurtma muvaffaqiyatli amalga oshirildi. % ta mashina sotib olindi', car_count;
end;
$$;

call buy_car(1,2,1);
πŸ”₯6πŸ‘2πŸ‘1πŸ‘Œ1πŸ†’1😘1
Kodingda try bor-u, lekin hayotingda catch ishlamayapti. Xatolarni toβ€˜gβ€˜rilash oβ€˜rniga, ularni "feature" deb nomlab qoβ€˜yayotgan backendchisan. Katta loyihalar qilishni orzu qilasan, lekin hozircha faqat res.send("Hello World") bilan yuribsan.

Sen oβ€˜zingni zoβ€˜r deb bilasan, lekin MongoDB'dagi dokumentlar sendan mustahkamroq qaror qabul qiladi. Frontendni yomon koβ€˜rasan, chunki sen qilgan API-larga hech kim request yubormaydi. Aslida esa backendchilar ham frontendchilar kabi "loading..." holatida yashaydi.

Xoβ€˜jayin, sen senior boβ€˜lishni orzu qilasan, lekin GitHub commitlaring "Initial commit" bilan tugagan. Agar sening dasturlash yoβ€˜lingni "ping" qilib tekshirsak, request timeout berib ketadi.

Lekin sendan yaxshi backendchi chiqadi!"
🀣2πŸ€·β€β™‚1πŸ‘1πŸ”₯1😁1πŸ“1
😠Roast me as hard as you can based on everything you know about me. Don’t hold back even a little bit. I can take it all. In uzbek
Bu so'rovga nisbatan chatgpt javobi πŸ’€πŸ‘†
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ”₯3πŸ‘¨β€πŸ’»2❀‍πŸ”₯1πŸ‘1
I'M_DEVELOPERπŸ‘¨β€πŸ’»
https://youtu.be/itkUJSYrg1U?si=Mdc0tFlSjPGui1jt
Assalomu alaykum ancha manfaatli boβ€˜ldi hammaga ko'rishni tavsiya qilaman
πŸ”₯3πŸ‘2πŸ‘1😍1
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ‘5πŸ”₯1πŸ₯°1πŸ‘1😘1
Ramazon oyi barchamizga barokatli boβ€˜lsin.
Ramazon muborak yaqinlarimπŸŒ•
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸŽ‰4πŸ‘2❀1❀‍πŸ”₯1⚑1πŸ₯°1🀩1πŸ•Š1πŸ’‹1πŸ˜‡1
Qachonki mukammal senior dasturchi boβ€˜lganingda...
πŸ”₯3😁2πŸ’‹1
Qizig'i shu oy yaqinda yangi chiqgandida bugun to'lishga yaqin (#umr oβ€˜tyapti...) !
⚑4πŸ”₯1πŸ˜‡1πŸ’˜1
Og'ir damlar koβ€˜pga bormaydi
Ammo og'ir damlar ichida qolgan bardoshli insonlar koβ€˜pga boradi
...)
πŸ‘4πŸ”₯3⚑1πŸ’‹1
#esda qolarli kunlardan...)🫠
πŸ”₯4⚑2πŸ‘2❀‍πŸ”₯1
#bahor...)
πŸ”₯2⚑1πŸ‘1πŸ•Š1