Skip to content

Commit

Permalink
feature: add config db and create model to user data
Browse files Browse the repository at this point in the history
  • Loading branch information
hiramgabriel1 committed Jan 24, 2024
1 parent 110d7ca commit 58feacc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"dotenv": "^16.3.1",
"dotenv": "^16.4.0",
"express-expeditious": "^4.0.0",
"mongoose": "^8.1.0",
"morgan": "^1.10.0"
Expand Down
13 changes: 13 additions & 0 deletions src/config/mongo.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import mongoose from "mongoose";

const db = process.env.URI

const connection = async () => {
try {
await mongoose.connect(db)
} catch (error) {
console.error(error)
}
}

export default connection
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import express, { Express } from "express";
import morgan from "morgan";
import cors from "cors";
import dotenv from "dotenv"
import connection from "./config/mongo.config";

dotenv.config()
connection()

const app: Express = express();
const port = process.env.PORT;
Expand Down
45 changes: 45 additions & 0 deletions src/model/user.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import mongoose from "mongoose";

const user = new mongoose.Schema({
username: {
type: String,
require: true,
maxLength: 40,
},

lastName: {
type: String,
require: true,
maxLength: 40,
},

city: {
type: String,
require: true,
maxLenght: 20,
},

mountPrestamo: {
type: Number,
require: true,
},

totalInteres: {
type: Number,
},

totalSumadoInteres: {
type: Number,
},

mount: {
type: Number,
},
});

export const userModel = mongoose.model("users", user);
// Javascript -> tipado dinamico
// example const username = "jafete"

// TypeScript -> tipado fuerte
// example -> const username: string = "jafete"

0 comments on commit 58feacc

Please sign in to comment.