-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
203 additions
and
238 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import axios from "axios"; | ||
import mongoose from "mongoose"; | ||
|
||
import { BASE_URL } from "~/utils"; | ||
// import { ITask } from "~/~/models/Task"; | ||
|
||
// Get user's tasks | ||
export async function getTasksByUserId(userId: string) { | ||
try { | ||
const response = await axios.get(`${BASE_URL}/tasks/${userId}`); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
const data = response.data; | ||
|
||
return data; | ||
} catch (err) { | ||
console.log(err); // Handle | ||
} | ||
} | ||
|
||
// Create | ||
export async function createTask(userId: string, title: string) { | ||
try { | ||
const response = await fetch("http://localhost:5050/api/tasks", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
userId, | ||
title, | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
return data; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
// Delete | ||
export async function deleteTaskById( | ||
userId: string, | ||
taskId: mongoose.Types.ObjectId, | ||
) { | ||
try { | ||
const response = await axios.delete( | ||
`${BASE_URL}/tasks/${userId}/${taskId}`, | ||
); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
const data = response.data; | ||
|
||
console.log(data); | ||
|
||
return data; | ||
} catch (err) { | ||
console.log(err); // Handle | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from "axios"; | ||
|
||
import { BASE_URL } from "~/utils"; | ||
|
||
// Get user by ID | ||
export async function getUserById(userId: string) { | ||
try { | ||
const response = await axios.get(`${BASE_URL}/users`, { | ||
params: userId, | ||
}); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
const data = response.data; | ||
return data; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
// Create user | ||
export async function createUser( | ||
username: string, | ||
email: string, | ||
password: string, | ||
) { | ||
try { | ||
const response = await fetch(`${BASE_URL}/users`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
username, | ||
email, | ||
password, | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`${response.status} ${response.statusText}`); | ||
} | ||
|
||
const data = await response.json(); | ||
console.log(data); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.