-
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.
Update noteModel, package.json, userController, server, folderRoutes,…
… and noteController
- Loading branch information
1 parent
72c6689
commit 324af10
Showing
12 changed files
with
198 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Router } from "express"; | ||
import { createNote} from '../controller/noteController.js'; | ||
|
||
|
||
// Create a new router instance | ||
const router = Router(); | ||
|
||
/** | ||
* Route for creating a new note. | ||
* POST /user/create/note/new | ||
* The actual logic for user creation is encapsulated in the createFolder function within the folderController. | ||
*/ | ||
router.post('/user/create/note/new', createNote); | ||
|
||
export default router; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Function to generate a formatted date and time string | ||
function getFormattedDateTime() { | ||
const date = new Date(); | ||
const year = date.getFullYear(); | ||
const month = String(date.getMonth() + 1).padStart(2, '0'); // Add leading zero for single-digit months | ||
const day = String(date.getDate()).padStart(2, '0'); | ||
const hours = String(date.getHours()).padStart(2, '0'); | ||
const minutes = String(date.getMinutes()).padStart(2, '0'); | ||
const seconds = String(date.getSeconds()).padStart(2, '0'); | ||
|
||
return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`; | ||
} | ||
|
||
export default getFormattedDateTime; |
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,24 @@ | ||
// Define a generic type for the model's document type | ||
type TModel<T> = { | ||
find: (conditions: any) => Promise<T[]>; // Adjust return type if needed | ||
}; | ||
import mongoose from "mongoose"; | ||
|
||
export async function getModelBy<T> ( | ||
model: TModel<T>, | ||
key: string, | ||
value: mongoose.Types.ObjectId | ||
): Promise<T[]> { | ||
try { | ||
const records = await model.find({ [key]: value }); | ||
return records; | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.log(error.message); | ||
} | ||
} | ||
|
||
// Explicitly return undefined if function reaches here (unexpected) | ||
return []; | ||
} | ||
|
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,16 @@ | ||
import casual from "casual"; | ||
import mongoose from "mongoose"; | ||
import dateTimeGenerator from "./dateTimeGenerator.js"; | ||
|
||
const no_name = `default-${dateTimeGenerator()}`; | ||
|
||
export function generateNote(folderId: mongoose.Types.ObjectId, userId: mongoose.Types.ObjectId) { | ||
return { | ||
fileName: casual.title, // Use casual.title for filenames | ||
content: casual.sentences(2), | ||
userId: userId,// Generate random content sentences | ||
folderId: folderId, | ||
}; | ||
} | ||
|
||
// Path: backend_veenote/src/utilities/fakeDataGenerator.ts |