Skip to content

Commit e1849f3

Browse files
authored
Merge pull request #15 from weaponsforge/dev
v1.0.2
2 parents ce7e70d + 2465892 commit e1849f3

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**apidocs-swagger-ui** features a simple Todo notes-taking CRUP API borrowed from [`todo-next`](https://github.com/weaponsforge/todo-next)'s server.
44

5-
This repository aims to test using [swagger-ui](https://github.com/swagger-api/swagger-ui) for creating an modern, responsive and interactive REST API documentations and to familiarize oneself with the [OpenAPI](https://spec.openapis.org/oas/v3.1.0) specifications, v3.1.0 as of this writing.
5+
This repository aims to test using [swagger-ui](https://github.com/swagger-api/swagger-ui) for creating modern, responsive and interactive REST API documentations and to familiarize oneself with the [OpenAPI](https://spec.openapis.org/oas/v3.1.0) specifications, v3.1.0 as of this writing.
66

77
![screenshot](/assets/thumbnail.png)
88

docs/src/swagger/swagger-config.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ paths:
3535
application/json:
3636
schema:
3737
$ref: '#/components/schemas/Todo'
38+
example:
39+
title: Read a Book
40+
description: Read books about the Earth
41+
content: Earth is the 3rd planet on the solar system, 3/4 made up of water
3842
required: true
3943
responses:
4044
'200':
@@ -56,11 +60,16 @@ paths:
5660
description: Update an existing Todo by ID
5761
operationId: updateTodo
5862
requestBody:
59-
description: Update an existing Todo in the database. The `_id` field is required while the `title`, `description` and `content` fields are optional.
63+
description: Update an existing Todo in the database. The `id` field is required while the `title`, `description` and `content` fields are optional.
6064
content:
6165
application/json:
6266
schema:
6367
$ref: '#/components/schemas/Todo'
68+
example:
69+
id: 63027bf42e28a411ed43b440
70+
title: Play a Game
71+
description: Games to play this week
72+
content: Choices are tic-tac-toe, hide and seek and jumping rope
6473
required: true
6574
responses:
6675
'200':
@@ -80,7 +89,7 @@ paths:
8089
tags:
8190
- todo
8291
summary: Deletes a Todo
83-
descriptionn: Delete a Todo
92+
description: Delete a Todo by ID. Returns the data of a deleted Todo, on successful deletion.
8493
operationId: deleteTodo
8594
parameters:
8695
- name: id
@@ -149,7 +158,7 @@ components:
149158
properties:
150159
_id:
151160
type: string
152-
example: ggdasu34773647f
161+
example: 63027c032e28a411ed43b442
153162
title:
154163
type: string
155164
example: My Favorite Things
@@ -159,6 +168,12 @@ components:
159168
content:
160169
type: string
161170
example: The things I love in this world is Brownie and you.
171+
createdAt:
172+
type: date-time
173+
example: 2022-08-21T18:40:03.512Z
174+
updatedAt:
175+
type: date-time
176+
example: 2022-08-22T11:06:09.245Z
162177
requestBodies:
163178
Todo:
164179
description: Todo object that needs to be added to the database

src/classes/todo/todo.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class Todo {
3232
* @returns {Object} Updated Todo
3333
*/
3434
async updatetodo (params) {
35-
const id = params._id
36-
const keys = ['title', 'description', 'content']
35+
const keys = ['id', 'title', 'description', 'content']
3736

3837
const data = keys.reduce((acc, item) => {
3938
if (params[item] !== undefined) {
@@ -45,7 +44,7 @@ class Todo {
4544

4645
try {
4746
const result = await TodoSchema.findOneAndUpdate(
48-
{ _id: id },
47+
{ _id: data.id },
4948
data,
5049
{ returnOriginal: false }
5150
)

src/controllers/todo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ module.exports.createTodo = async (req, res, next) => {
1919

2020
// Update an existing Todo document
2121
module.exports.updateTodo = async (req, res, next) => {
22-
const { _id, title, description, content } = req.body
22+
const { id, title, description, content } = req.body
2323

2424
try {
2525
const doc = await Todo.updatetodo({
26-
_id,
26+
id,
2727
title,
2828
description,
2929
content

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require('dotenv').config()
2+
require('./utils/db')
3+
24
const express = require('express')
35
const cors = require('cors')
46
const cookieParser = require('cookie-parser')
@@ -8,7 +10,6 @@ const PORT = process.env.PORT || 3001
810

911
const { corsOptions } = require('./utils/cors_options')
1012
const controllers = require('./controllers')
11-
require('./utils/db')
1213

1314
// Enable if you're behind a reverse proxy (i.e., Heroku)
1415
app.set('trust proxy', 1)

0 commit comments

Comments
 (0)