Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions api/src/quest/application/combined-course-blueprint-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ const detachOrganization = async (request, h) => {
};

const attachOrganizations = async (request, h, dependencies = { combinedCourseBlueprintOrganizationSerializer }) => {
const combinedCourseBlueprintId = request.params.blueprintId;
const results = await usecases.attachOrganizationsToCombinedCourseBlueprint({
combinedCourseBlueprintId,
organizationIds: request.payload['organization-ids'],
});
return h
.response(
dependencies.combinedCourseBlueprintOrganizationSerializer.serialize({ ...results, combinedCourseBlueprintId }),
)
.code(201);
const combinedCourseBlueprintId = request.params.blueprintId;
const results = await usecases.attachOrganizationsToCombinedCourseBlueprint({
combinedCourseBlueprintId,
organizationIds: request.payload['organization-ids'],
});
return h
.response(
dependencies.combinedCourseBlueprintOrganizationSerializer.serialize({ ...results, combinedCourseBlueprintId }),
)
.code(201);
};

const findByOrganizationId = async (request, _, dependencies = { combinedCourseBlueprintSerializer }) => {
Expand All @@ -70,6 +70,7 @@ const findOverviewById = async (request, _, dependencies = { combinedCourseBluep
const combinedCourseBlueprint = await usecases.findCombinedCourseBlueprintById({
id: request.params.blueprintId,
});
console.log({combinedCourseBlueprint})
return dependencies.combinedCourseBlueprintOverviewSerializer.serialize(combinedCourseBlueprint);
};

Expand Down
53 changes: 50 additions & 3 deletions api/src/shared/infrastructure/utils/dependency-injection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
import { glob } from 'node:fs/promises';
import {join} from 'node:path'
import {cwd} from 'node:process'
import { pathToFileURL } from 'node:url';

import _ from 'lodash';

import { tracing } from '../open-telemetry/helpers.js';

function injectDefaults(defaults, targetFn) {
return (args) => targetFn(Object.assign(Object.create(defaults), args));
async function isForDomain(value) {
return async (filePath) => {
const mod = await import(pathToFileURL(filePath).href);
const ExportedClass = mod.default;

if (value instanceof ExportedClass) { /* ... */ }
}
}

function makeInjectDefaults(boundedContext) {
return (defaults, targetFn) => {
return async (args) => {
console.log(targetFn)
const result = await targetFn(Object.assign(Object.create(defaults), args))
console.log({ result })
const pathToModels = join(cwd(), 'src', 'quest', 'domain', 'models')
console.log({ pathToModels })
const modelFiles = []
for await (const entry of glob(join(pathToModels, '**/*.js')))
modelFiles.push(entry)

let found = false

for (const filePath of modelFiles) {
const mod = await import(pathToFileURL(filePath).href);
const ExportedClass = mod[Object.keys(mod)[0]];
if (typeof ExportedClass !== 'function') {
continue;
}
console.log(result.constructor.name, filePath, typeof ExportedClass, ExportedClass)
if (result instanceof ExportedClass) {
found = true
}
}

if (!found) {
throw Error('NOT A DOMAIN MODEL')
}

console.log({ found })

return result
}
}
}

/**
Expand Down Expand Up @@ -59,7 +106,7 @@ export function injectDependencies(toBeInjected, dependencies, boundedContext =
const wrapped = tracing.spanify(`${boundedContext.name}->${name}`, value, () => ({
attributes: defaultAttributes,
}));
return [name, _.partial(injectDefaults, wrappedDependencies, wrapped)()];
return [name, _.partial(makeInjectDefaults(boundedContext.name), wrappedDependencies, wrapped)()];
} else {
return [name, injectDependencies(value, dependencies)];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe('Quest | Acceptance | Application | Combined course blueprint Route ',
await databaseBuilder.commit();
});

it('should return 200', async function () {
it.only('should return 200', async function () {
const options = {
method: 'GET',
url: `/api/organizations/${organization.id}/combined-course-blueprints/${combinedCourseBlueprint.id}`,
Expand Down
Loading