Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platzi master reto - José Díaz #59

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Services updated to mongodb lib
jocdiazm committed Jun 16, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fcddd436bc0719f3e81eb787a19d7e24879242b9
66 changes: 4 additions & 62 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,65 +1,5 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,node,linux
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,node,linux

### Linux ###
*~
@@ -214,7 +154,9 @@ temp/
# Ignore all local history of files
.history
.ionide
.vscode

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node,linux



5 changes: 3 additions & 2 deletions src/lib/mongo.js
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ class MongoLib {
}

getAll(collection, query) {
console.log(this.connect(db => {console.log(db)}))
//console.log(this.connect(db => {console.log(db)}))
return this.connect().then((db) => {
return db.collection(collection).find(query).toArray();
});
@@ -53,7 +53,7 @@ class MongoLib {
}

create(collection, data) {
console.log(data)
//console.log(data)
return this.connect()
.then((db) => {
return db.collection(collection).insertOne(data);
@@ -62,6 +62,7 @@ class MongoLib {
}

update(collection, id, data) {
//console.log(collection,id,data)
return this.connect()
.then((db) => {
return db
13 changes: 7 additions & 6 deletions src/routes/categories.js
Original file line number Diff line number Diff line change
@@ -42,17 +42,18 @@ function categoriesApi(app) {
});

router.post("/", async function (req, res, next) {
console.log(req.body);

const { body: category } = req;

console.log( { body: category } )
//console.log(req.body);
//console.log( { body: category } )
try {
//const createdCategoryId = await Promise.resolve(categoriesMock[0].categoryId);
const createdCategoryId = await categoriesService.createCategory({category});

res.status(201).json({
data: createdCategoryId,
message: "Categorie created",
message: "Category created",
});
} catch (err) {
console.log("something happened");
@@ -61,7 +62,7 @@ function categoriesApi(app) {
});

router.put("/:categoryId", async function (req, res, next) {
const { body: category } = req.body;
const { body: category } = req;
const { categoryId } = req.params;
try {
//const updatedCategoryId = await Promise.resolve(categoriesMock[0].categoryId);
@@ -72,7 +73,7 @@ function categoriesApi(app) {

res.status(200).json({
data: updatedCategoryId,
message: "Categorie updated",
message: "Category updated",
});
} catch (err) {
console.log("something happened");
@@ -93,7 +94,7 @@ function categoriesApi(app) {

res.status(200).json({
data: deletedCategoryId,
message: "Movie Deleted",
message: "Category deleted",
});
} catch (err) {
console.log("something happened");
5 changes: 3 additions & 2 deletions src/services/categories.js
Original file line number Diff line number Diff line change
@@ -24,14 +24,15 @@ class CategoriesService {

async createCategory({ category }) {
//const createdMovieId = await Promise.resolve(categoriesMock[0].categoryId);

const createdCategoryId = await this.mongoDB.create(this.collection, category);
console.log("creando categoria")
//console.log("creando categoria")
return createdCategoryId || [];
}

async updateCategory({ categoryId, category } = {}) {
// const updatedCategory = await Promise.resolve(categoriesMock[0].categoryId);
//console.log("updateando categoria")
//console.log(categoryId,category)
const updatedCategory = await this.mongoDB.update(
this.collection,
categoryId,