Code Monkey home page Code Monkey logo

vietloka-internal's Introduction

Vietloka-internal

Build Status Coverage Status

A RESTful API server for Vietloka project, built with the help of Yeoman and generator-rest.

NOTE: this is only just a barebone (for now). Almost all logic hasn't been implemented. Tests will fail (I haven't actually rewrite tests yet). Devs will cry foul. But, this is currently just a barebone, so please bear with me for a while. At least, development server should work normally.

More documentation will be added later :p.

Commands

After you generate your project, these commands are available in package.json.

npm test # test using Jest
npm run test:unit # run unit tests
npm run test:integration # run integration tests
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run dev # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs

Directory structure

Overview

You can customize the src and api directories.

src/
├─ api/
│  ├─ user/
│  │  ├─ controller.js
│  │  ├─ index.js
│  │  ├─ index.test.js
│  │  ├─ model.js
│  │  └─ model.test.js
│  └─ index.js
├─ services/
│  ├─ express/
│  ├─ mongoose/
│  ├─ passport/
│  └─ your-service/
├─ app.js
├─ config.js
└─ index.js

src/api/

Here is where the API endpoints are defined. Each API has its own folder.

src/api/some-endpoint/model.js

It defines the Mongoose schema and model for the API endpoint. Any changes to the data model should be done here.

src/api/some-endpoint/controller.js

This is the API controller file. It defines the main router middlewares which use the API model.

src/api/some-endpoint/index.js

This is the entry file of the API. It defines the routes using, along other middlewares (like session, validation etc.), the middlewares defined in the some-endpoint.controller.js file.

services/

Here you can put helpers, libraries and other types of modules which you want to use in your APIs.

vietloka-internal's People

Contributors

abn-volk avatar chitoge avatar sieugee avatar trannhuthuat96 avatar

Watchers

 avatar  avatar  avatar  avatar

vietloka-internal's Issues

API tìm kiếm nhà

Hiện tại chưa có API để tìm các địa điểm homestay. Trước hết cần có API phục vụ tìm kiếm trên bản đồ (lấy đầu vào là các điểm cực Bắc/Nam/Đông/Tây). Trả về không cần chi tiết, chỉ cần địa chỉ, tên chủ hộ, tiêu đề (xem vấn đề phần House), để khi nhấn vào sẽ có chi tiết trong tab mới.

Đồng thời, có thể thêm các điều kiện tìm kiếm như trong schema của House nếu thích. Nhưng trước hết, tớ nghĩ nên tìm được trên bản đồ đã.

Vấn đề về schema của House

Hiện tại hình như schema chưa ổn lắm.

Thứ nhất, các thuộc tính của House được gộp hơi tuỳ tiện. Tớ nghĩ là nên bỏ hẳn việc gộp đi (vì đằng nào đọc JSON ra cũng như thế), hoặc gộp nhóm vào một cách bài bản.

Thứ hai, giá điện với nước tưởng là thuê trọ thôi, còn homestay thì tính luôn vào giá thuê phòng?

Thứ ba, chưa có phần mô tả chi tiết để người chủ giới thiệu kĩ về nhà mình. Hơn nữa, có nên cho thêm phần tiêu đề không?

Thứ tư, tớ nghĩ nên để tổng số chỗ / số đã thuê hơn là số đã thuê / số còn trống.

Thứ năm, cái others là gì tớ chưa hiểu lắm. Cái này có phải tương tự với phần mô tả không? Nếu thế thì để array làm form rách việc lắm.

Cách đưa ảnh lên trang web

Làm thế nào để đăng ảnh lên nhỉ (ví dụ ảnh đại diện, hình ảnh căn nhà...). Hiện tại mình đang để String nhỉ? Thực ra thì nếu mệt quá ta dùng tạm link đến các dịch vụ chia sẻ ảnh khác cũng được, nhưng thế hơi chắp vá và khi điền thông tin sẽ bất tiện.

Lỗi API House

Hành động: POST tạo House mới với đủ các tham số
Kết quả đúng: Trả về đối tượng House hoặc id House
Thực tế: Trả về đối tượng không rõ tên tuổi, trong đó có chứa user và một id khác không phải của house vừa tạo nên không thể xem được house đó.

Hành động: GET House theo id
Kết quả đúng: Trả về đầy đủ House
Thực tế: Trả về đối tượng dạng như trên, id là id của House nhưng không có bất kì thuộc tính nào khác ngoài owner.

Ca sử dụng khách nhận homestay

Khi trình bày mình có nói với thầy rất nhiều thứ về việc tài chính, thanh toán, v.v. Bây giờ phần này mình nên làm thế nào?

Lỗi API Guest và Host

Các bước thực hiện:

  1. Đăng kí người dùng là guest/host thành công

  2. Truy cập guests/self hoặc hosts/self

Cả hai đều gây lỗi tương tự nhau:

CastError: Cast to ObjectId failed for value "self" at path "_id" for model "Host"
    at MongooseError.CastError (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/error/cast.js:26:11)
    at ObjectId.cast (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/schema/objectid.js:147:13)
    at ObjectId.castForQuery (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/schema/objectid.js:187:15)
    at cast (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/cast.js:229:32)
    at Query.cast (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/query.js:2915:12)
    at Query.findOne (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/query.js:1395:10)
    at /home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/query.js:2728:21
    at Promise._execute (/home/pnh/Documents/vietloka-internal/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/home/pnh/Documents/vietloka-internal/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/home/pnh/Documents/vietloka-internal/node_modules/bluebird/js/release/promise.js:79:10)
    at Query.exec (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/query.js:2722:17)
    at Query.then (/home/pnh/Documents/vietloka-internal/node_modules/mongoose/lib/query.js:2770:15)
    at show (/home/pnh/Documents/vietloka-internal/src/api/host/controller.js:23:6)
    at Layer.handle [as handle_request] (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/layer.js:95:5)
    at /home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/index.js:281:22
    at param (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/index.js:354:14)
    at param (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/index.js:365:14)
    at Function.process_params (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/index.js:410:3)
    at next (/home/pnh/Documents/vietloka-internal/node_modules/express/lib/router/index.js:275:10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.