Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 10:36
    dependabot[bot] edited #1346
  • 10:25
    dependabot[bot] edited #1346
  • 10:25
    dependabot[bot] synchronize #1346
  • 10:25
    dependabot[bot] edited #1346
  • 09:42
    dependabot[bot] edited #1346
  • 09:41
    Romakita labeled #1359
  • 09:41
    Romakita commented #1359
  • 09:08
    Romakita closed #1359
  • 08:31
    Romakita synchronize #1359
  • 08:16
    Romakita synchronize #1359
  • 08:14
    Romakita synchronize #1359
  • Apr 18 08:11
    Romakita opened #1359
  • Apr 17 19:37
    dependabot[bot] edited #1346
  • Apr 17 19:36
    dependabot[bot] edited #1346
  • Apr 17 19:36
    dependabot[bot] synchronize #1346
  • Apr 17 19:36
    dependabot[bot] edited #1346
  • Apr 17 19:36
    dependabot[bot] edited #1346
  • Apr 17 19:35
    Romakita labeled #1358
  • Apr 17 19:35
    Romakita commented #1358
  • Apr 17 19:20
    Romakita closed #1358
Carlos Herrera
@carlos-herrera-cervantes
@Post('/logout')
  @Summary('Invalidate session of user')
  @(Status(204).Description('Success'))
  @(Status(400).Description('Missing or invalid token supplied'))
    .ContentType('application/json')
    .Examples([ badRequest ])
  @(Status(500).Description('Internal Server Error'))
    .ContentType('application/json')
    .Examples([ internalServerError ])
  logout(): string {
    return 'OK';
  }
7 replies
I don't see much complexity in that method. What could this error be due to?
Carlos Herrera
@carlos-herrera-cervantes
The truth is that I have been experiencing very strange errors. Now my model injection is not working. I have my following models:
This is my base model
import { ObjectID } from '@tsed/mongoose';
import { Property, Default, Format } from '@tsed/schema';

export class Base {
  @ObjectID()
  _id: string;

  @Property()
  @Format('date-time')
  @Default(Date.now)
  createdAt: Date = new Date();

  @Property()
  @Format('date-time')
  @Default(Date.now)
  updatedAt: Date = new Date();
}
Then I have a User model that inherits from it
1 reply
Then I inject my service like this:
import { Inject, Service } from "@tsed/common";
import { MongooseModel } from "@tsed/mongoose";
import { User } from '../models/User';
import { BaseService } from './BaseService';

@Service()
export class UserService extends BaseService {

  constructor(@Inject(User) private user: MongooseModel<User>) {
    super(user);
  }

  async getAllAsync(): Promise<User[]> {
    return await this.user.find().lean();
  }

}
And when I make a call to that method (getAllAsync) from my controller it throws an error like this
Carlos Herrera
@carlos-herrera-cervantes
{
  "name": "TypeError",
  "message": "model.find is not a function",
  "status": 500,
  "errors": []
}
As if the model was not injecting well. Curiously all this worked before updating the version of the @ tsed / common
Carlos Herrera
@carlos-herrera-cervantes
Well I think I will migrate to NestJS, its community it's more larger
Romain Lenzotti
@Romakita
@carlos-herrera-cervantes Give me a repo example. I’ll help you.
I think the version isn’t related. Or maybe you haven’t updated all tsed dependencies with the same version
Send me message in PM
But if you prefer to work with NestJS, let’s go ;)
Gabriel Peruchi
@gabriel-peruchi
1.PNG
2.PNG
4.PNG
3.PNG
When validating for the model in the controller parameter, it becomes null in an empty string, the date in an invalid date and the number in 0. How do I make them remain null? This started to happen after migrating from v5.
Philip Diffenderfer
@ClickerMonkey
Have you tried adding @Optional() ?
Gabriel Peruchi
@gabriel-peruchi
I tried now, it didn't work, they are still like this. I want them to remain null.
3.PNG
Romain Lenzotti
@Romakita
The dataInstalacao is incorrectly decorated. Use collectionOf but the typing isn’t an array. Remove colllectionOf or fix the typing
And you want to use Date type, use @Property(Date)
Gabriel Peruchi
@gabriel-peruchi
Thanks for the suggestion, I will fix it. But about the parameters not being null when they arrive at the controller, any suggestions? I need them to remain null. Would it be something related to JsonMapper?
Romain Lenzotti
@Romakita
@gabriel-peruchi fix the decorator and it should fix the null param
Remove the collectionOf please
I think the problem is related to the wrong usage with collectionOf and the given type.
CollectionOf must only be used to set the item type when your prop is an Array/Set/Map
Gabriel Peruchi
@gabriel-peruchi
But why don't the other attributes also remain null? The "logo" that is a reference is transformed into an empty string, the "name" that is a string is transformed into an empty string and the "valorInstalacao" that is a number is transformed to 0. These attributes have no CollectionOf.
Romain Lenzotti
@Romakita
You’ve right isn’t normal
Sorry I’m pretty tired ^^So haven’t seen the issue
Can you open issue please. I’ll try to fix it asap
Romain Lenzotti
@Romakita
Ok I found the issue. Ajv try to coerce types :( probably a new change since recent version
Romain Lenzotti
@Romakita
Fixed with latest version
Jordan Davidson
@from-nibly
Are there any examples of how to validate a patch body so that it doesn't include properties outside of the specified type? i.e. How do I exclude things like id and created_at from being modified by a patch/put endpoint call and make sure that the body doesn't include those things.
3 replies
Gabriel Peruchi
@gabriel-peruchi

Fixed with latest version

Thank you very much. Good work! :)

Romain Lenzotti
@Romakita
;)
Gabriel Peruchi
@gabriel-peruchi
Ajv does not allow "null" for an object type attribute. Is this a problem or am I doing something wrong?
2.PNG
4.PNG
3.PNG
8.PNG
Romain Lenzotti
@Romakita
You have Nullable decorator to allow null on any prop
Gabriel Peruchi
@gabriel-peruchi
I've tried, nothing has changed
1.PNG
2.PNG