Skip to content

Commit a08ddef

Browse files
authored
Merge pull request #3 from jesieldotdev/new-db
fix: typing
2 parents c312504 + ba439c3 commit a08ddef

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/app/api/posts/[id]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const PUT = async (req: Request) => {
2020
try {
2121
const { title, slug, author_id} = await req.json();
2222
const id = req.url.split("posts/")[1];
23-
updatePost(id, title, slug, author_id);
23+
updatePost({id, title, slug, author_id});
2424
return NextResponse.json({ message: "OK" }, { status: 200 });
2525
} catch (err) {
2626
return NextResponse.json({message: 'Error'}, {status: 500})

src/app/api/users/[id]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const PUT = async (req: Request) => {
2222
try {
2323
const { username, password, email, is_admin } = await req.json();
2424
const id = req.url.split("users/")[1];
25-
updateUser(id, username, password, is_admin);
25+
updateUser({id, username,email, password, is_admin});
2626
return NextResponse.json({ message: "OK" }, { status: 200 });
2727
} catch (err) {
2828
return NextResponse.json({message: 'Error'}, {status: 500})
@@ -35,7 +35,7 @@ export const DELETE = async (req: Request) => {
3535

3636
const user = getUserById(id);
3737

38-
if (!post) {
38+
if (!user) {
3939
return NextResponse.json({ message: "Error" }, { status: 404 });
4040
}
4141
deleteUser(id);

src/app/lib/users_controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import supabase from '../../config/database'; // Importando o cliente Supabase
22

33
interface UserInputProps{
4-
id?:number
4+
id?:number | string
55
username: string
66
email: string
77
password: string
@@ -48,7 +48,7 @@ export const deleteUser = async (id: string) => {
4848
};
4949

5050
// Atualizar um post pelo id
51-
export const updateUser = async ({username, password, is_admin, email}:UserInputProps) => {
51+
export const updateUser = async ({username, password, is_admin, email, id}:UserInputProps) => {
5252
const { data, error } = await supabase
5353
.from('users')
5454
.update({ username, email, password, is_admin })

src/models/User.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ interface User {
44
id: string;
55
username: string;
66
password: string;
7-
createsAt: Date
8-
is_admin: boolean; // O Supabase geralmente lida com datas como strings em formato ISO
7+
createsAt: Date;
8+
is_admin: boolean;
99
}
1010

11-
interface UserInputProps{
12-
username: string
13-
password: string
14-
is_admin: boolean
11+
interface UserInputProps {
12+
username: string;
13+
password: string;
14+
is_admin: boolean;
1515
}
1616

1717
class UserModel {
18-
// Função para obter todos os posts
18+
// Função para obter todos os usuários
1919
static async getAllUsers(): Promise<User[]> {
2020
const { data, error } = await supabase
2121
.from("users")
@@ -28,8 +28,8 @@ class UserModel {
2828
return data as User[];
2929
}
3030

31-
// Função para criar um novo post
32-
static async createUser(UserInputProps): Promise<User> {
31+
// Função para criar um novo usuário
32+
static async createUser({ username, password, is_admin }: UserInputProps): Promise<User> {
3333
const { data, error } = await supabase
3434
.from("users")
3535
.insert([{ username, password, is_admin }])
@@ -42,7 +42,7 @@ class UserModel {
4242
return data as User;
4343
}
4444

45-
// Função para obter um post por ID
45+
// Função para obter um usuário por ID
4646
static async getUserById(userId: string): Promise<User | null> {
4747
const { data, error } = await supabase
4848
.from("users")
@@ -57,11 +57,11 @@ class UserModel {
5757
return data as User | null;
5858
}
5959

60-
// Função para atualizar um post
61-
static async updateUser(UserInputProps): Promise<User> {
60+
// Função para atualizar um usuário
61+
static async updateUser(userId: string, { username, password, is_admin }: UserInputProps): Promise<User> {
6262
const { data, error } = await supabase
6363
.from("users")
64-
.update({ username, password, is_admin})
64+
.update({ username, password, is_admin })
6565
.eq("id", userId)
6666
.single();
6767

@@ -72,7 +72,7 @@ class UserModel {
7272
return data as User;
7373
}
7474

75-
// Função para deletar um post
75+
// Função para deletar um usuário
7676
static async deleteUser(userId: string): Promise<void> {
7777
const { error } = await supabase
7878
.from("users")

0 commit comments

Comments
 (0)