class-transformer#classToClass TypeScript Examples

The following examples show how to use class-transformer#classToClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListProvidersService.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async execute({ user_id }: IRequest): Promise<User[]> {
    let users = await this.cacheProvider.recover<User[]>(
      `providers-list:${user_id}`,
    );

    if (!users) {
      users = await this.usersRepository.findAllProviders({
        expect_user_id: user_id,
      });

      await this.cacheProvider.save(
        `providers-list:${user_id}`,
        classToClass(users),
      );
    }

    return users;
  }
Example #2
Source File: equip.ts    From j3pz-web with MIT License 6 votes vote down vote up
public setEmbed(idx: number, level: number): Equip {
        if (idx < this.embed.count && level >= 0) {
            const equip = classToClass(this);
            equip.embedding[idx] = {
                index: idx,
                level,
            };
            return equip;
        }
        return this;
    }
Example #3
Source File: equip.ts    From j3pz-web with MIT License 6 votes vote down vote up
public setEnhance(enhance?: Enhance | null): Equip {
        if (enhance) {
            const equip = classToClass(this);
            equip.enhance = enhance;
            return equip;
        }
        const equip = classToClass(this);
        equip.enhance = null;
        return equip;
    }
Example #4
Source File: ProfileController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async update(request: Request, response: Response): Promise<Response> {
    const { email, name, oldPassword, password } = request.body;
    const { id: user_id } = request.user;

    const updateProfile = container.resolve(UpdateProfileService);

    const updatedUser = await updateProfile.execute({
      user_id,
      email,
      name,
      oldPassword,
      password,
    });

    delete updatedUser?.password;

    return response.status(200).json(classToClass(updatedUser));
  }
Example #5
Source File: ProfileController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async show(request: Request, response: Response): Promise<Response> {
    const { id: user_id } = request.user;

    const showProfile = container.resolve(ShowProfileService);

    const user = await showProfile.execute({ user_id });

    return response.status(200).json(classToClass(user));
  }
Example #6
Source File: ListProviderAppointmentsService.ts    From GoBarber with MIT License 6 votes vote down vote up
public async execute({
    provider_id,
    day,
    month,
    year,
  }: IRequest): Promise<Appointment[]> {
    let appointments = await this.cacheProvider.recover<Appointment[]>(
      `provider-appointments:${provider_id}:${day}-${month}-${year}`,
    );

    if (!appointments) {
      appointments = await this.appointmentsRepository.findAllInDayFromProvider(
        {
          provider_id,
          day,
          month,
          year,
        },
      );

      await this.cacheProvider.save({
        key: `provider-appointments:${provider_id}:${day}-${month}-${year}`,
        value: classToClass(appointments),
      });
    }

    return appointments;
  }
Example #7
Source File: ProviderAppointmentsController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async index(request: Request, response: Response): Promise<Response> {
    const provider_id = request.user.id;
    const { day, month, year } = request.query;

    const listProviderAppointments = container.resolve(
      ListProviderAppointmentsService,
    );

    const appointments = await listProviderAppointments.execute({
      provider_id,
      day: Number(day),
      month: Number(month),
      year: Number(year),
    });

    return response.json(classToClass(appointments));
  }
Example #8
Source File: ProvidersController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async index(request: Request, response: Response): Promise<Response> {
    const user_id = request.user.id;

    const listProviders = container.resolve(ListProvidersService);

    const providers = await listProviders.execute({
      user_id,
    });

    return response.json(classToClass(providers));
  }
Example #9
Source File: ListProviderAppointmentsService.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async execute({
    provider_id,
    day,
    month,
    year,
  }: IRequest): Promise<Appointment[]> {
    const cacheKey = `provider-appointments:${provider_id}:${year}-${month}-${day}`;

    let appointments = await this.cacheProvider.recover<Appointment[]>(
      cacheKey,
    );

    if (!appointments) {
      appointments = await this.appointmentsRepository.findAllInDayFromProvider(
        {
          provider_id,
          day,
          month,
          year,
        },
      );

      await this.cacheProvider.save(cacheKey, classToClass(appointments));
    }
    return appointments;
  }
Example #10
Source File: SessionsController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { email, password } = request.body;

    const authenticateUser = container.resolve(AuthenticateUserService);

    const { user, token } = await authenticateUser.execute({ email, password });

    return response.status(200).json({ user: classToClass(user), token });
  }
Example #11
Source File: ProfileController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async show(request: Request, response: Response): Promise<Response> {
    const user_id = request.user.id;

    const showProfileService = container.resolve(ShowProfileService);

    const user = await showProfileService.execute({ user_id });

    return response.json(classToClass(user));
  }
Example #12
Source File: ProfileController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async update(request: Request, response: Response): Promise<Response> {
    const user_id = request.user.id;
    const { name, email, old_password, password } = request.body;

    const updateUser = container.resolve(UpdateProfileService);

    const user = await updateUser.execute({
      user_id,
      name,
      email,
      old_password,
      password,
    });

    return response.json(classToClass(user));
  }
Example #13
Source File: SessionsController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { email, password } = request.body;

    const authenticateUser = container.resolve(AuthenticateUserService);

    const { user, token } = await authenticateUser.execute({
      email,
      password,
    });

    return response.json({ user: classToClass(user), token });
  }
Example #14
Source File: UserAvatarController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async update(request: Request, response: Response): Promise<Response> {
    const updateUserAvatar = container.resolve(UpdateUserAvatarService);

    const user = await updateUserAvatar.execute({
      user_id: request.user.id,
      avatar_filename: request.file.filename,
    });

    return response.json(classToClass(user));
  }
Example #15
Source File: UsersController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { name, email, password } = request.body;

    const createUser = container.resolve(CreateUserService);

    const user = await createUser.execute({
      name,
      email,
      password,
    });

    return response.json(classToClass(user));
  }
Example #16
Source File: ProviderAppointmentsController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async index(request: Request, response: Response): Promise<Response> {
    const { id: provider_id } = request.user;
    const { day, month, year } = request.query;

    const listProviderAppointments = container.resolve(
      ListProviderAppointmentsService,
    );

    const appointments = await listProviderAppointments.execute({
      provider_id,
      day: Number(day),
      month: Number(month),
      year: Number(year),
    });

    return response.status(200).json(classToClass(appointments));
  }
Example #17
Source File: ProvidersController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async index(request: Request, response: Response): Promise<Response> {
    const { id: user_id } = request.user;

    const listProviders = container.resolve(ListProvidersService);

    const providers = await listProviders.execute({
      user_id,
    });

    return response.status(200).json(classToClass(providers));
  }
Example #18
Source File: UserAvatarController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async update(request: Request, response: Response): Promise<Response> {
    const updateUserAvatar = container.resolve(UpdateUserAvatarService);

    const user = await updateUserAvatar.execute({
      user_id: request.user.id,
      avatarFilename: request.file.filename,
    });

    delete user.password;

    return response.status(200).json(classToClass(user));
  }
Example #19
Source File: ListProviderAppointmentsService.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async execute({
    provider_id,
    day,
    month,
    year,
  }: IRequest): Promise<Appointment[]> {
    const cacheKey = `provider-appointments:${provider_id}:${year}-${month}-${day}`;

    let appointments = await this.cacheProvider.recover<Appointment[]>(
      cacheKey,
    );

    if (!appointments) {
      appointments = await this.appointmentsRepository.findAllInDayFromProvider(
        {
          provider_id,
          day,
          month,
          year,
        },
      );

      await this.cacheProvider.save(cacheKey, classToClass(appointments));
    }

    return appointments;
  }
Example #20
Source File: ProfileController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async show(req: Request, res: Response): Promise<Response> {
    const user_id = req.user.id;

    const showProfile = container.resolve(ShowProfileService);

    const user = await showProfile.execute({ user_id });

    return res.json(classToClass(user));
  }
Example #21
Source File: ProfileController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async update(req: Request, res: Response): Promise<Response> {
    const user_id = req.user.id;
    const { name, email, password, old_password } = req.body;

    const updateProfile = container.resolve(UpdateProfileService);

    const user = await updateProfile.execute({
      name,
      email,
      old_password,
      password,
      user_id,
    });

    return res.json(classToClass(user));
  }
Example #22
Source File: SessionsController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async create(req: Request, res: Response): Promise<Response> {
    const { email, password } = req.body;

    const authenticateUser = container.resolve(AuthenticateUserService);

    const { user, token } = await authenticateUser.execute({ email, password });

    return res.json({ user: classToClass(user), token });
  }
Example #23
Source File: UserAvatarController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async update(req: Request, res: Response): Promise<Response> {
    const updateUserAvatar = container.resolve(UpdateUserAvatarService);

    const user = await updateUserAvatar.execute({
      user_id: req.user.id,
      avatarFilename: req.file.filename,
    });

    return res.json(classToClass(user));
  }
Example #24
Source File: UsersController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async create(req: Request, res: Response): Promise<Response> {
    const { name, email, password } = req.body;

    const createUser = container.resolve(CreateUserService);

    const user = await createUser.execute({ name, email, password });

    return res.json(classToClass(user));
  }
Example #25
Source File: ProviderAppointmentsController.ts    From hotseat-api with MIT License 6 votes vote down vote up
async index(
    request: Request,
    response: Response,
  ): Promise<Response<Appointments[]>> {
    const { day, year, month } = request.query;
    const provider_id = request.user.id;

    const listProviderAppointments = container.resolve(
      ListProviderAppointmentsService,
    );

    const appointments = await listProviderAppointments.execute({
      day: Number(day),
      year: Number(year),
      month: Number(month),
      provider_id,
    });

    return response.json(classToClass(appointments));
  }
Example #26
Source File: ProvidersController.ts    From hotseat-api with MIT License 6 votes vote down vote up
async index(request: Request, response: Response): Promise<Response<User[]>> {
    const { id: user_id } = request.user;

    const listProvidersService = container.resolve(ListProvidersService);

    const providers = await listProvidersService.execute({
      exceptUserId: user_id,
    });

    return response.json(classToClass(providers));
  }
Example #27
Source File: ListProvidersService.ts    From hotseat-api with MIT License 6 votes vote down vote up
public async execute({ exceptUserId }: IRequest): Promise<User[]> {
    const providersListCacheKey = getProvidersListCacheKey(exceptUserId);

    let providers = await this.cacheProvider.get<User[]>(providersListCacheKey);

    if (!providers) {
      providers = await this.usersRepository.findProviders({
        exceptUserId,
      });

      await this.cacheProvider.save<User[]>(
        providersListCacheKey,
        classToClass(providers),
      );
    }

    return providers;
  }
Example #28
Source File: SessionsController.ts    From hotseat-api with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { email, password } = request.body;

    const authenticateUserService = container.resolve(AuthenticateUserService);

    const { user, token, refreshToken } = await authenticateUserService.execute(
      {
        email,
        password,
      },
    );

    return response.json({
      user: classToClass(user),
      token,
      refreshToken,
    });
  }
Example #29
Source File: UserAvatarController.ts    From hotseat-api with MIT License 6 votes vote down vote up
public async update(request: Request, response: Response): Promise<Response> {
    const { id: user_id } = request.user;
    const avatarFilename = request.file?.filename;

    if (!avatarFilename) {
      return response.status(400).json({ error: 'Please, send a avatar file' });
    }

    const uploadAvatarService = container.resolve(UploadAvatarService);

    const userWithAvatar = await uploadAvatarService.execute({
      user_id,
      avatarFilename,
    });

    return response.json(classToClass(userWithAvatar));
  }