typeorm#FindOneOptions TypeScript Examples

The following examples show how to use typeorm#FindOneOptions. 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: ApiApplicationController.ts    From Designer-Server with GNU General Public License v3.0 6 votes vote down vote up
/**
   * id를 사용하여 Appplication을 반환합니다.</br>
   * Stages와 trafficConfigs를 포함합니다.
   * @param applicationId 
   * @param request 
   */
  @Get("/{applicationId}")
  @Security("jwt")
  public async getDetail(
    @Path('applicationId') applicationId: number,
    @Request() request: exRequest
  ): Promise<Application>{
    const appRepo = getRepository(Application);
    const findOptions: FindOneOptions = {
      relations: ["stages", "trafficConfigs"],
      where: {
        id: applicationId,
        userId: request.user.id
      }
    }
    
    const app = await appRepo.findOne(findOptions);
    if(!app) { throw new ApplicationError(404, ERROR_CODE.APPLICATION.APPLICATION_NOT_FOUND) }

    return Promise.resolve(app);
  }
Example #2
Source File: ApiApplicationController.ts    From Designer-Server with GNU General Public License v3.0 6 votes vote down vote up
@Post("/{applicationId}/stages")
  @Security("jwt")
  public async postStage(
    @Request() request: exRequest,
    @Path('applicationId') applicationId: number
  ){
    const appRepo = getRepository(Application);
    const findOptions: FindOneOptions = {
      relations: ["stages", "trafficConfigs"],
      where: {
        id: applicationId,
        userId: request.user.id
      }
    }
    
    const app = await appRepo.findOne(findOptions);
    if(!app) { throw new ApplicationError(404, ERROR_CODE.APPLICATION.APPLICATION_NOT_FOUND) }

    const stage = new Stage();
    stage.name = stage.name = `${app.nextVersion}`;
    stage.userId = request.user.id;
    stage.applicationId = app.id;

    await getManager().transaction(async transactionEntityManager => {
      await transactionEntityManager.save(app);
      await transactionEntityManager.save(stage);
    });
    this.setStatus(201);
    return Promise.resolve(stage);
  }
Example #3
Source File: BaseSqlRepository.ts    From node-experience with MIT License 6 votes vote down vote up
async exist(condition: Record<string, any> | Record<string, any>[], select: string[], initThrow = false): Promise<any>
    {
        const conditionMap: FindOneOptions = {
            select,
            where: condition,
            loadEagerRelations: false
        };

        const exist = await this.repository.findOne(conditionMap as FindOneOptions<T>);

        if (initThrow && !exist)
        {
            throw new NotFoundException(this.entityName);
        }

        return exist;
    }
Example #4
Source File: CashCurrencyService.ts    From cashcash-desktop with MIT License 6 votes vote down vote up
async find(isoCode1: string, manager?: EntityManager) {
        const criteria: FindOneOptions<CashCurrency> = {
            select: ['id', 'name', 'isoCode', 'symbol'],
            where: {
                isoCode: isoCode1,
            },
        };

        if (!manager) {
            manager = getManager();
        }
        const repository = manager.getCustomRepository(CashCurrencyRepository);
        return await repository.findOne(criteria);
    }
Example #5
Source File: User.ts    From fosscord-server with GNU Affero General Public License v3.0 6 votes vote down vote up
static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
		return await User.findOneOrFail(
			{ id: user_id },
			{
				...opts,
				select: [...PublicUserProjection, ...(opts?.select || [])],
			}
		);
	}
Example #6
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
findOne(
    id?: string | number | Date | ObjectID,
    options?: FindOneOptions<E>,
  ): Promise<E | undefined>;
Example #7
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
findOne(options?: FindOneOptions<E>): Promise<E | undefined>;
Example #8
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
findOne(
    conditions?: FindConditions<E>,
    options?: FindOneOptions<E>,
  ): Promise<E | undefined>;
Example #9
Source File: polymorphic.repository.ts    From typeorm-polymorphic with MIT License 5 votes vote down vote up
public async findOne(
    idOrOptionsOrConditions?:
      | string
      | number
      | Date
      | ObjectID
      | FindConditions<E>
      | FindOneOptions<E>,
    optionsOrConditions?: FindConditions<E> | FindOneOptions<E>,
  ): Promise<E | undefined> {
    const polymorphicMetadata = this.getPolymorphicMetadata();

    if (Object.keys(polymorphicMetadata).length === 0) {
      return idOrOptionsOrConditions &&
        (typeof idOrOptionsOrConditions === 'string' ||
          typeof idOrOptionsOrConditions === 'number' ||
          typeof idOrOptionsOrConditions === 'object') &&
        optionsOrConditions
        ? super.findOne(
            idOrOptionsOrConditions as number | string | ObjectID | Date,
            optionsOrConditions as FindConditions<E> | FindOneOptions<E>,
          )
        : super.findOne(
            idOrOptionsOrConditions as FindConditions<E> | FindOneOptions<E>,
          );
    }

    const entity =
      idOrOptionsOrConditions &&
      (typeof idOrOptionsOrConditions === 'string' ||
        typeof idOrOptionsOrConditions === 'number' ||
        typeof idOrOptionsOrConditions === 'object') &&
      optionsOrConditions
        ? await super.findOne(
            idOrOptionsOrConditions as number | string | ObjectID | Date,
            optionsOrConditions as FindConditions<E> | FindOneOptions<E>,
          )
        : await super.findOne(
            idOrOptionsOrConditions as FindConditions<E> | FindOneOptions<E>,
          );

    if (!entity) {
      return entity;
    }

    return this.hydratePolymorphs(entity, polymorphicMetadata);
  }