Skip to content

Commit

Permalink
Merged from develop
Browse files Browse the repository at this point in the history
V.1.1
  • Loading branch information
hasimy-as committed Jan 10, 2021
2 parents f8d3349 + bbbf80b commit ef05e16
Show file tree
Hide file tree
Showing 36 changed files with 20,416 additions and 3,535 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT = YOUR_PORT
MONGO_URI = YOUR_MONGO_URI
54 changes: 54 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
env:
node: true
es6: true
mocha: true

extends: 'eslint:recommended'

parser: 'babel-eslint'

parserOptions:
ecmaVersion: 6
sourceType: 'module'
ecmaFeatures:
jsx: true
modules: true
experimentalObjectRestSpread: true

rules:
handle-callback-err: 2
no-debugger: 2
no-fallthrough: 2
eol-last: 1
no-irregular-whitespace: 1
no-mixed-spaces-and-tabs: [1, smart-tabs]
no-trailing-spaces: 1
no-new-require: 2
no-undef: 2
no-unreachable: 2
no-unused-vars: [1, { 'vars': 'all', 'args': 'none' }]
no-console: 2
max-len: [2, 150, 4]
prefer-arrow-callback:
- error
- allowNamedFunctions: true
indent:
- error
- 2
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
no-lonely-if: 2
no-else-return: 2
no-empty-function: 1
no-eq-null: 2
no-var: 2
strict:
- error
- global
69 changes: 63 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,55 @@
# Codebase-Restify
A back end project template using Restify as a Node.js framework.

## Project Status
A back end project template using Restify as a Node.js framework.

[![Github license](https://img.shields.io/badge/License-MIT-yellow.svg)](https://raw.githubusercontent.com/hasimy-as/Codebase-Restify/master/LICENSE)
[![npm](https://img.shields.io/npm/v/npm.svg)](https://www.npmjs.com/)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://gitHub.com/hasimy-as/Codebase-Restify)
[![Code coverage](https://img.shields.io/badge/coverage-97%25-green)](https://gitHub.com/hasimy-as/Codebase-Restify)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code-of-conduct.md)
<br />

## What's inside?

## Version
A quick peek at some of the top-level files and directories found in this project.

```console

.
├── app
├── test
├── .env.example
├── .eslintrc.yml
├── .gitignore
├── code-of-conduct.md
├── LICENSE
├── package-lock.json
├── package.json
├── README.md
├── server.js


```

1. **`/app`**: This directory contains all of the code related to the back-end, such as APIs, configurations, database connections, and library files.

2. **`/test`**: Tests for this projects are stored here. This project uses [Mocha](https://mochajs.org) as a testing framework.

3. **`.env.example`**: This is an environment configuration file for your designated project Port and also your MongoDB URI. Rename it to .env and you're good to go.

4. **`.eslintrc.yml`**: This is the main configuration file for Eslint. Eslint is a pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript.

5. **`code-of-conduct.md`**: Code of Conduct. The rules shape and differentiate good practices and attitudes from the wrong ones when creating software or when making decisions on a crucial or delicate issue regarding a programming project.

Current app version is on v1.0.
6. **`LICENSE`**: Codebase-Restify is licensed under the MIT license.

7. **`package-lock.json`**: This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. (You won't change this file directly).

8. **`package.json`**: A manifest file for Node.js projects. Includes things such as metadata (the project's name, author, etc.). This file is how npm knows which packages to install for you.

9. **`README.md`**: It's the file you're reading now! This text file contains useful informations about your project.

10. **`server.js`**: This file is where the Restify server listens to the server which Port is already configured by you in the .env file.

## Usage

Expand All @@ -24,6 +63,14 @@ npm run dev
# Run in production
npm start
# Unit / Integration testing
npm run test
npm run cover // To create a coverage report
# Check linting
npm run lint
npm run lint-fix // To fix linting problem
# Initialize mongodb
mongod
```
Expand All @@ -32,6 +79,7 @@ mongod

```
# Routes
ROOT {{url}}/
POST {{url}}/api/users
GET {{url}}/api/users
Expand All @@ -41,9 +89,18 @@ DELETE {{url}}/api/users/:userId
```

## Licensed under [MIT](https://raw.githubusercontent.com/hasimy-as/Codebase-Restify/master/LICENSE)
## Version

- Current app version is on v1.1 🖥️

## License and Conduct

- MIT © [Hasimy Md's License](https://raw.githubusercontent.com/hasimy-as/Codebase-Restify/master/LICENSE)
- [Code of Conduct](code-of-conduct.md)

## Collaboration

Want to collaborate? Fork the project and be a collaborator now!
👨🏻‍💻 Want to collaborate? Fork the project and be a collaborator now!

Happy coding!

Expand Down
102 changes: 51 additions & 51 deletions app/api/components/user/api_depository/request/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,64 @@ const request = require('./request');
const response = require('../response/response');

class User {
async createUser(payload) {
let userData = {
userId: uuid(),
...payload,
};
async createUser(payload) {
let userData = {
userId: uuid(),
...payload,
};

const user = await request.insertOne(userData);
if (user.err) {
return wrapper.error(
'fail',
'Failed to create user',
CODE.INTERNAL_ERROR,
);
}
const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}
const user = await request.insertOne(userData);
if (user.err) {
return wrapper.error(
'fail',
'Failed to create user',
CODE.INTERNAL_ERROR,
);
}
const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}

async updateUser(payload) {
const findUserId = await response.findOne({ userId: payload.userId });
if (findUserId.err) {
return wrapper.error('error', 'User not found!', CODE.NOT_FOUND);
}
async updateUser(payload) {
const findUserId = await response.findOne({ userId: payload.userId });
if (findUserId.err) {
return wrapper.error('error', 'User not found!', CODE.NOT_FOUND);
}

const user = await request.updateOne(
{ userId: payload.userId },
{ $set: { ...payload } },
);
if (user.err) {
return wrapper.error(
'fail',
'Failed to update user',
CODE.INTERNAL_ERROR,
);
}
const user = await request.updateOne(
{ userId: payload.userId },
{ $set: { ...payload } },
);
if (user.err) {
return wrapper.error(
'fail',
'Failed to update user',
CODE.INTERNAL_ERROR,
);
}

const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}
const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}

async deleteUser(payload) {
const findUserId = await response.findOne({ userId: payload.userId });
if (findUserId.err) {
return wrapper.error('error', 'User not found!', CODE.NOT_FOUND);
}
async deleteUser(payload) {
const findUserId = await response.findOne({ userId: payload.userId });
if (findUserId.err) {
return wrapper.error('error', 'User not found!', CODE.NOT_FOUND);
}

const user = await request.deleteOne({ userId: payload.userId });
if (user.err) {
return wrapper.error(
'fail',
'Failed to delete user',
CODE.INTERNAL_ERROR,
);
}
const user = await request.deleteOne({ userId: payload.userId });
if (user.err) {
return wrapper.error(
'fail',
'Failed to delete user',
CODE.INTERNAL_ERROR,
);
}

const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}
const { data } = user;
return wrapper.data(data, '', CODE.SUCCESS);
}
}

module.exports = User;
24 changes: 12 additions & 12 deletions app/api/components/user/api_depository/request/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ const env = require('../../../../../config/config');
const collection = 'user';

const insertOne = async (payload) => {
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.insertOne(payload);
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.insertOne(payload);
};

const updateOne = async (params, payload) => {
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.updateOne(params, payload);
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.updateOne(params, payload);
};

const deleteOne = async (params, payload) => {
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.deleteOne(params, payload);
const db = new mongodb(env.get('/mongo'));
db.setCollection(collection);
return db.deleteOne(params, payload);
};

module.exports = {
insertOne,
updateOne,
deleteOne,
insertOne,
updateOne,
deleteOne,
};
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const User = require('./main');

const createUser = async (payload) => {
const user = new User();
return user.createUser(payload);
const user = new User();
return user.createUser(payload);
};

const updateUser = async (payload) => {
const user = new User();
return user.updateUser(payload);
const user = new User();
return user.updateUser(payload);
};

const deleteUser = async (payload) => {
const user = new User();
return user.deleteUser(payload);
const user = new User();
return user.deleteUser(payload);
};

module.exports = {
createUser,
updateUser,
deleteUser,
createUser,
updateUser,
deleteUser,
};
18 changes: 9 additions & 9 deletions app/api/components/user/api_depository/request/request_schema.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const joi = require('joi');

const createUser = joi.object({
name: joi.string().required(),
address: joi.string().required(),
name: joi.string().required(),
address: joi.string().required(),
});

const updateUser = joi.object({
userId: joi.string().guid().required(),
name: joi.string().required(),
address: joi.string().required(),
userId: joi.string().guid().required(),
name: joi.string().required(),
address: joi.string().required(),
});

const deleteUser = joi.object({
userId: joi.string().guid().required(),
userId: joi.string().guid().required(),
});

module.exports = {
createUser,
updateUser,
deleteUser,
createUser,
updateUser,
deleteUser,
};
Loading

0 comments on commit ef05e16

Please sign in to comment.