forked from b00tc4mp/isdi-parttime-202406
-
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.
add some json-bbdd files b00tc4mp#207
- Loading branch information
1 parent
4523002
commit 5e56cb2
Showing
15 changed files
with
145 additions
and
48 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,52 @@ | ||
{"users":[{"id":0,"name":"Limón","birth_date":"1985-01-04","phone":"+34 111111111","email":"[email protected]","password":"12345678"},{"id":1,"name":"Borja","birth_date":"1995-08-30","phone":"+34 987654321","email":"[email protected]","password":"12345678"},{"id":2,"name":"Angela","birth_date":"1998-02-06","phone":"+34 669488278","email":"[email protected]","password":"holamellamoangela"}]} | ||
{ | ||
"users": [ | ||
{ | ||
"id": 0, | ||
"name": "Limón", | ||
"birth_date": "1985-01-04", | ||
"phone": "+34 111111111", | ||
"email": "[email protected]", | ||
"password": "12345678" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Borja", | ||
"birth_date": "1995-08-30", | ||
"phone": "+34 987654321", | ||
"email": "[email protected]", | ||
"password": "12345678" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "Pepito", | ||
"birth_date": "1995-08-30", | ||
"phone": "+34 987654321", | ||
"email": "[email protected]", | ||
"password": "12345678" | ||
}, | ||
{ | ||
"id": 3, | ||
"name": "Rafa", | ||
"birth_date": "1983-02-07", | ||
"phone": "+34 123456789", | ||
"email": "[email protected]", | ||
"password": "12345678" | ||
}, | ||
{ | ||
"id": 4, | ||
"name": "Rafa", | ||
"birth_date": "1983-02-07", | ||
"phone": "+34 123456789", | ||
"email": "[email protected]", | ||
"password": "12345678" | ||
}, | ||
{ | ||
"id": 5, | ||
"name": "ventu", | ||
"birth_date": "2000-01-02", | ||
"phone": "+34 987654321", | ||
"email": "[email protected]", | ||
"password": "123456789" | ||
} | ||
] | ||
} |
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 CredentialsError(message) { | ||
const instance = new Error(message); | ||
Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(instance, CredentialsError); | ||
} | ||
return instance; | ||
} | ||
|
||
CredentialsError.prototype = Object.create(Error.prototype); | ||
|
||
CredentialsError.prototype.name = "CredentialsError" | ||
|
||
module.exports = CredentialsError |
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,7 @@ | ||
const CredentialsError = require("./credentials.js") | ||
const NotFoundError = require("./not-found.js") | ||
|
||
module.exports = { | ||
NotFoundError, | ||
CredentialsError, | ||
} |
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 NotFoundError(message) { | ||
const instance = new Error(message); | ||
Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(instance, NotFoundError); | ||
} | ||
return instance; | ||
} | ||
|
||
NotFoundError.prototype = Object.create(Error.prototype); | ||
|
||
NotFoundError.prototype.name = "NotFoundError" | ||
|
||
module.exports = NotFoundError |
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,9 @@ | ||
const { users } = require("../scripts") | ||
|
||
users.createOne({ | ||
name: "pepito", | ||
birthDate: "2020-01-01", | ||
phone: "123456789", | ||
email: "[email protected]", | ||
password: "passswordddd" | ||
}) |
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,3 @@ | ||
const users = require("./users"); | ||
|
||
module.exports = { users }; |
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 |
---|---|---|
|
@@ -2,10 +2,7 @@ const fs = require("fs") | |
const path = require("path") | ||
const read = require("./read-all.js") | ||
|
||
|
||
|
||
function createOne(data) { | ||
|
||
// destructuring the object data to extract its properties | ||
// user don´t pass id property as they do not know that info | ||
const { name, birthDate, phone, email, password } = data; | ||
|
@@ -31,19 +28,10 @@ function createOne(data) { | |
JSON.stringify({ users: users }), | ||
"utf-8", | ||
(err) => { | ||
console.log(err); | ||
if (err) throw err | ||
} | ||
); | ||
}); | ||
} | ||
|
||
|
||
create({ | ||
name: "Portal", | ||
birthDate: "1995-11-03", | ||
phone: "+34 123456789", | ||
email: "[email protected]", | ||
password: "holamellamoportal" | ||
}) | ||
|
||
module.exports = createOne |
28 changes: 28 additions & 0 deletions
28
staff/angela-bernaldez/json-bbdd/scripts/users/delete-one.js
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,28 @@ | ||
const fs = require("fs") | ||
const path = require("path") | ||
const read = require("./read-all.js") | ||
const {NotFoundError, CredentialsError} = require("../../errors") | ||
|
||
function deleteOne(id, password) { | ||
read((users) => { | ||
const user = users.filter((_user) => _user.id === id)[0] | ||
|
||
if (!user) throw new NotFoundError("User not found") | ||
|
||
if (!(user.password === password)) throw new CredentialsError("Password doesn't match") | ||
|
||
const newUsers = users.filter((_user) => !(_user.id === id)); | ||
|
||
fs.writeFile( | ||
path.join(__dirname, "../../database/users.json"), | ||
JSON.stringify({ users: newUsers }), | ||
"utf-8", | ||
(err) => { | ||
if (err) throw err | ||
} | ||
); | ||
}); | ||
} | ||
|
||
module.exports = deleteOne | ||
|
Empty file.
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,13 @@ | ||
const createOne = require("./create-one.js"); | ||
const deleteOne = require("./delete-one.js"); | ||
const readAll = require("./read-all.js"); | ||
const readOne = require("./read-one.js"); | ||
const updateById = require("./update-by-id.js"); | ||
|
||
module.exports = { | ||
createOne, | ||
deleteOne, | ||
readAll, | ||
readOne, | ||
updateById, | ||
}; |
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
Empty file.