Skip to content

Commit

Permalink
feat: allow selecting which versions to export
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Dec 18, 2024
1 parent 1f390cd commit dae5036
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 12 deletions.
13 changes: 11 additions & 2 deletions packages/app-api/src/controllers/Module/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { moduleProtectionMiddleware } from '../../middlewares/moduleProtectionMi
import { AllowedFilters, RangeFilterCreatedAndUpdatedAt } from '../shared.js';
import { ITakaroQuery } from '@takaro/db';
import { ModuleService } from '../../service/Module/index.js';
import { ModuleCreateAPIDTO, ModuleOutputDTO, ModuleUpdateDTO } from '../../service/Module/dto.js';
import {
ModuleCreateAPIDTO,
ModuleExportOptionsDTO,
ModuleOutputDTO,
ModuleUpdateDTO,
} from '../../service/Module/dto.js';

import { ModuleTransferDTO, ICommand, ICommandArgument, ICronJob, IFunction, IHook } from '@takaro/modules';
import { PermissionCreateDTO } from '../../service/RoleService.js';
Expand Down Expand Up @@ -149,12 +154,16 @@ export class ModuleController {
})
@Post('/:id/export')
@ResponseSchema(ModuleExportDTOAPI)
async export(@Req() req: AuthenticatedRequest, @Params() params: ParamId) {
async export(@Req() req: AuthenticatedRequest, @Params() params: ParamId, @Body() options: ModuleExportOptionsDTO) {
const service = new ModuleService(req.domainId);
const mod = await service.findOne(params.id);
if (!mod) throw new errors.NotFoundError('Module not found');
const versions = await service.findVersions({ filters: { moduleId: [params.id] } });

if (options.versionIds) {
versions.results = versions.results.filter((_) => options.versionIds?.includes(_.id));
}

const preparedVersions = await Promise.all(
versions.results.map(
async (version) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,30 @@ const tests = [
},
}),
),
new IntegrationTest<ModuleOutputDTO>({
group,
snapshot: false,
name: 'Can select which versions to export',
setup,
test: async function () {
// Create a module, tag 2 versions, export only one
const tagRes = await this.client.module.moduleVersionControllerTagVersion({
moduleId: this.setupData.id,
tag: '1.0.0',
});
await this.client.module.moduleVersionControllerTagVersion({
moduleId: this.setupData.id,
tag: '2.0.0',
});

const exportRes = await this.client.module.moduleControllerExport(this.setupData.id, {
versionIds: [tagRes.data.data.id],
});

expect(exportRes.data.data.versions).to.have.length(1);
expect(exportRes.data.data.versions[0].tag).to.equal('1.0.0');
},
}),
// #endregion Import/export
// #region Versioning
new IntegrationTest<ModuleOutputDTO>({
Expand Down
6 changes: 6 additions & 0 deletions packages/app-api/src/service/Module/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,9 @@ export class InstallModuleDTO extends TakaroDTO<InstallModuleDTO> {
@IsOptional()
systemConfig?: string;
}

export class ModuleExportOptionsDTO extends TakaroDTO<ModuleExportOptionsDTO> {
@IsUUID('4', { each: true })
@IsOptional()
versionIds?: string[];
}
63 changes: 53 additions & 10 deletions packages/lib-apiclient/src/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,6 +5327,19 @@ export interface ModuleExportDTOAPI {
*/
meta: MetadataOutput;
}
/**
*
* @export
* @interface ModuleExportOptionsDTO
*/
export interface ModuleExportOptionsDTO {
/**
*
* @type {Array<string>}
* @memberof ModuleExportOptionsDTO
*/
versionIds?: Array<string>;
}
/**
*
* @export
Expand Down Expand Up @@ -17566,10 +17579,15 @@ export const ModuleApiAxiosParamCreator = function (configuration?: Configuratio
* Exports a module to a format that can be imported into another Takaro instance. This endpoint will export all known versions of the module Required permissions: `READ_MODULES`
* @summary Export a module
* @param {string} id
* @param {ModuleExportOptionsDTO} [moduleExportOptionsDTO] ModuleExportOptionsDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
moduleControllerExport: async (id: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
moduleControllerExport: async (
id: string,
moduleExportOptionsDTO?: ModuleExportOptionsDTO,
options: RawAxiosRequestConfig = {},
): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists('moduleControllerExport', 'id', id);
const localVarPath = `/module/{id}/export`.replace(`{${'id'}}`, encodeURIComponent(String(id)));
Expand All @@ -17586,9 +17604,16 @@ export const ModuleApiAxiosParamCreator = function (configuration?: Configuratio

// authentication domainAuth required

localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
localVarRequestOptions.data = serializeDataIfNeeded(
moduleExportOptionsDTO,
localVarRequestOptions,
configuration,
);

return {
url: toPathString(localVarUrlObj),
Expand Down Expand Up @@ -17630,7 +17655,7 @@ export const ModuleApiAxiosParamCreator = function (configuration?: Configuratio
},
/**
* Imports a module from a format that was exported from another Takaro instance Required permissions: `MANAGE_MODULES`
* @summary Import a module version
* @summary Import a module
* @param {ModuleTransferDTO} [moduleTransferDTO] ModuleTransferDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down Expand Up @@ -18081,14 +18106,20 @@ export const ModuleApiFp = function (configuration?: Configuration) {
* Exports a module to a format that can be imported into another Takaro instance. This endpoint will export all known versions of the module Required permissions: `READ_MODULES`
* @summary Export a module
* @param {string} id
* @param {ModuleExportOptionsDTO} [moduleExportOptionsDTO] ModuleExportOptionsDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async moduleControllerExport(
id: string,
moduleExportOptionsDTO?: ModuleExportOptionsDTO,
options?: RawAxiosRequestConfig,
): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ModuleExportDTOAPI>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.moduleControllerExport(id, options);
const localVarAxiosArgs = await localVarAxiosParamCreator.moduleControllerExport(
id,
moduleExportOptionsDTO,
options,
);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath =
operationServerMap['ModuleApi.moduleControllerExport']?.[localVarOperationServerIndex]?.url;
Expand Down Expand Up @@ -18125,7 +18156,7 @@ export const ModuleApiFp = function (configuration?: Configuration) {
},
/**
* Imports a module from a format that was exported from another Takaro instance Required permissions: `MANAGE_MODULES`
* @summary Import a module version
* @summary Import a module
* @param {ModuleTransferDTO} [moduleTransferDTO] ModuleTransferDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down Expand Up @@ -18427,11 +18458,18 @@ export const ModuleApiFactory = function (configuration?: Configuration, basePat
* Exports a module to a format that can be imported into another Takaro instance. This endpoint will export all known versions of the module Required permissions: `READ_MODULES`
* @summary Export a module
* @param {string} id
* @param {ModuleExportOptionsDTO} [moduleExportOptionsDTO] ModuleExportOptionsDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
moduleControllerExport(id: string, options?: RawAxiosRequestConfig): AxiosPromise<ModuleExportDTOAPI> {
return localVarFp.moduleControllerExport(id, options).then((request) => request(axios, basePath));
moduleControllerExport(
id: string,
moduleExportOptionsDTO?: ModuleExportOptionsDTO,
options?: RawAxiosRequestConfig,
): AxiosPromise<ModuleExportDTOAPI> {
return localVarFp
.moduleControllerExport(id, moduleExportOptionsDTO, options)
.then((request) => request(axios, basePath));
},
/**
* Required permissions: `READ_MODULES`
Expand All @@ -18445,7 +18483,7 @@ export const ModuleApiFactory = function (configuration?: Configuration, basePat
},
/**
* Imports a module from a format that was exported from another Takaro instance Required permissions: `MANAGE_MODULES`
* @summary Import a module version
* @summary Import a module
* @param {ModuleTransferDTO} [moduleTransferDTO] ModuleTransferDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down Expand Up @@ -18628,13 +18666,18 @@ export class ModuleApi extends BaseAPI {
* Exports a module to a format that can be imported into another Takaro instance. This endpoint will export all known versions of the module Required permissions: `READ_MODULES`
* @summary Export a module
* @param {string} id
* @param {ModuleExportOptionsDTO} [moduleExportOptionsDTO] ModuleExportOptionsDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ModuleApi
*/
public moduleControllerExport(id: string, options?: RawAxiosRequestConfig) {
public moduleControllerExport(
id: string,
moduleExportOptionsDTO?: ModuleExportOptionsDTO,
options?: RawAxiosRequestConfig,
) {
return ModuleApiFp(this.configuration)
.moduleControllerExport(id, options)
.moduleControllerExport(id, moduleExportOptionsDTO, options)
.then((request) => request(this.axios, this.basePath));
}

Expand All @@ -18654,7 +18697,7 @@ export class ModuleApi extends BaseAPI {

/**
* Imports a module from a format that was exported from another Takaro instance Required permissions: `MANAGE_MODULES`
* @summary Import a module version
* @summary Import a module
* @param {ModuleTransferDTO} [moduleTransferDTO] ModuleTransferDTO
* @param {*} [options] Override http request option.
* @throws {RequiredError}
Expand Down

0 comments on commit dae5036

Please sign in to comment.