Git Product home page Git Product logo

flugzeug's People

Contributors

guham avatar rodksquare avatar rodmg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flugzeug's Issues

TypeError if the Model belongs to User and without authentication

How to reproduce

  1. Add a new route
# with the api command:
$ flug api

Welcome to the Flugzeug API generator

? Model name: Test
? Would you like your model to belong to User? Yes
? Controller name: Test
? API Version: v1
? Needs authentication? No
   create app/models/Test.ts
   create app/controllers/v1/Test.ts


# or with the controller command:
$ flug controller

Welcome to the Flugzeug Controller generator

? Controller name: Test
? Model: Test
? API Version: v1
? Needs authentication? No
? Does the model belongs to User? Yes
   create app/controllers/v1/Test.ts
  1. then call it
curl --location --request GET 'http://localhost:8888/api/v1/test' \
--header 'Accept: application/json'

Result

TypeError: Cannot read property 'id' of undefined
    at flug/app/policies/General.ts:56:32

Problem

The req.session object is initialized in the Controller class, so it is available for all the next middleware. filterOwner, appendUser, filterRoles and isSelfUser middlewares use it to retrieve information about the user (from the JWT). But the req.session.jwt object is populated only when the validateJWT middleware is used when defining the route, which is not the case when the user chooses not to use authentication during the setup.

Relativate path in code generation

How to reproduce

Add new route

$ flug api MyNewRoute

then

Welcome to the Flugzeug API generator

? Model name: MyNewRoute
? Would you like your model to belong to User? Yes
? Controller name: MyNewRoute
? API Version: v1
? Needs authentication? Yes
   create app/models/MyNewRoute.ts
   create app/controllers/v1/MyNewRoute.ts

The next file is generate MyNewRoute.ts

import {
  Table,
  Column,
  DataType,
  ForeignKey,
  BelongsTo,
} from "sequelize-typescript";
import { BaseModel } from "../libraries/BaseModel";
import { User } from "./User";

@Table({
  tableName: "mynewroute",
})
export class MyNewRoute extends BaseModel<MyNewRoute> {

  @Column({
    type: DataType.STRING,
    allowNull: true,
    defaultValue: null,
  })
  name: string;

  @ForeignKey(() => User)
  @Column
  userId: number;

  @BelongsTo(() => User)
  user: User;

}

as you can see

import { BaseModel } from "../libraries/BaseModel"

use a relative path instead of

import { BaseModel } from "@/libraries/BaseModel"

This happens also with models, I didn't test for services

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.