Skip to content

Commit

Permalink
Solve error and merge conflicts for import
Browse files Browse the repository at this point in the history
  • Loading branch information
RidhamShah committed Sep 6, 2024
1 parent c1115fb commit e19b162
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,10 @@ export class FeatureFlagsController {
@Post('/import')
public async importFeatureFlags(
@Body({ validate: true }) featureFlags: FeatureFlagImportValidation,
@CurrentUser() currentUser: User,
@Req() request: AppRequest
): Promise<IImportError[]> {
return await this.featureFlagService.importFeatureFlags(featureFlags.files, request.logger);
return await this.featureFlagService.importFeatureFlags(featureFlags.files, currentUser, request.logger);
}
/**
* @swagger
Expand Down
12 changes: 6 additions & 6 deletions backend/packages/Upgrade/src/api/services/FeatureFlagService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FeatureFlagSegmentExclusion } from '../models/FeatureFlagSegmentExclusi
import { FeatureFlagRepository } from '../repositories/FeatureFlagRepository';
import { FeatureFlagSegmentInclusionRepository } from '../repositories/FeatureFlagSegmentInclusionRepository';
import { FeatureFlagSegmentExclusionRepository } from '../repositories/FeatureFlagSegmentExclusionRepository';
import { EntityManager, getConnection, In, DataSource } from 'typeorm';
import { EntityManager, In, DataSource } from 'typeorm';
import { InjectDataSource, InjectRepository } from '../../typeorm-typedi-extensions';
import { v4 as uuid } from 'uuid';
import {
Expand Down Expand Up @@ -331,7 +331,7 @@ export class FeatureFlagService {
return await executeTransaction(entityManager);
} else {
// Create a new transaction if no entity manager is provided
return await getConnection().transaction(async (manager) => {
return await this.dataSource.transaction(async (manager) => {
return await executeTransaction(manager);
});
}
Expand Down Expand Up @@ -505,7 +505,7 @@ export class FeatureFlagService {
return await executeTransaction(transactionalEntityManager);
} else {
// Create a new transaction if no entity manager is provided
return await getConnection().transaction(async (manager) => {
return await this.dataSource.transaction(async (manager) => {
return await executeTransaction(manager);
});
}
Expand Down Expand Up @@ -708,10 +708,10 @@ export class FeatureFlagService {

public async importFeatureFlags(
featureFlagFiles: IFeatureFlagFile[],
currentUser: User,
logger: UpgradeLogger
): Promise<IImportError[]> {
logger.info({ message: 'Import feature flags' });
const currentUser: User; // TODO: Get the current user from the request
const validatedFlags = await this.validateImportFeatureFlags(featureFlagFiles, logger);

const fileStatusArray = featureFlagFiles.map((file) => {
Expand All @@ -734,7 +734,7 @@ export class FeatureFlagService {
const createdFlags = [];

for (const featureFlag of validFiles) {
const createdFlag = await getConnection().transaction(async (transactionalEntityManager) => {
const createdFlag = await this.dataSource.transaction(async (transactionalEntityManager) => {
const newFlag = await this.addFeatureFlagInDB(
this.featureFlagValidatorToFlag(featureFlag),
currentUser,
Expand Down Expand Up @@ -822,7 +822,7 @@ export class FeatureFlagService {
}
})
.filter((key) => key !== null);
const existingFeatureFlags = await this.featureFlagRepository.find({ key: In(featureFlagsIds) });
const existingFeatureFlags = await this.featureFlagRepository.findBy({ key: In(featureFlagsIds) });

const validationErrors = await Promise.allSettled(
featureFlagFiles.map(async (featureFlagFile) => {
Expand Down

0 comments on commit e19b162

Please sign in to comment.