Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adhoc updates #32

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
1 change: 0 additions & 1 deletion scripts/src/commands/load/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default class LoadDatabase extends Command {
async insertServices(services: any[]): Promise<Map<string, ObjectId>> {
/** Maps the ID as defined in the JSON file to the ID in the database */
const serviceMap = new Map<string, ObjectId>();

// For each of the services, save the info not including
// the allowed connections
for (const service of services) {
Expand Down
1 change: 1 addition & 0 deletions scripts/src/commands/reset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Reset extends Command {
const { flags } = await this.parse(Reset);

// Connect to the database
console.log(`${flags.db} connection url`);
const client = await MongoClient.connect(flags.db);
await client.connect();

Expand Down
3 changes: 3 additions & 0 deletions src/reset/dtos/service.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@
import JSON from 'graphql-type-json';

@InputType()
export class ServiceInput {
@Field({ description: 'Human assigned ID' })
id: string;

@Field({ description: 'Name of the service' })
name: string;

@Field({ description: 'The icon image' })
icon: string;

@Field(() => JSON, { description: 'Parameters required of the service' })
parameters: any;

@Field(() => [String], { description: 'Array of human assigned IDs' })
allowedConnections: string[];

@Field(() => [String], { description: 'List of categories the service is a part of' })
categories: string[];

@Field(() => JSON, { description: 'The result of the service', nullable: true })
result?: any;

@Field()
description: string;

@Field(() => [String], { nullable: true })
resultParams?: string[];

@Field(() => JSON, { nullable: true })

Check warning on line 33 in src/reset/dtos/service.dto.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 33 in src/reset/dtos/service.dto.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
paramGroups?: any[];

Check warning on line 34 in src/reset/dtos/service.dto.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 35 in src/reset/dtos/service.dto.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 35 in src/reset/dtos/service.dto.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
3 changes: 2 additions & 1 deletion src/reset/reset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,59 @@
import { Bundle, BundleDocument } from '../bundles/bundles.model';

@Injectable()
export class ResetService {
constructor(
@InjectConnection() private readonly connection: Connection,
@InjectModel(DampLabService.name) private readonly serviceModel: Model<DampLabServiceDocument>,
@InjectModel(Category.name) private readonly categoryModel: Model<CategoryDocument>,
@InjectModel(Bundle.name) private readonly bundleModel: Model<BundleDocument>
) {}

async clearDatabase(): Promise<void> {
await this.connection.dropDatabase();
}

async loadData(services: ServiceInput[], categories: CategoryInput[], bundles: BundleInput[]): Promise<void> {
// First clear out the database
await this.clearDatabase();

// Make each service without the allowed connections and get back the
// mapping between human assigned IDs and MongoDB IDs
const serviceMap = await this.saveServices(services);

// Next, using the map determine the allowed connections
await this.updateAllowedConnections(services, serviceMap);

// Insert the categories
const categoryMap = await this.insertCategories(categories);

// Update the categories to have the service list using the categories
// field on the service
await this.updateServiceList(categories, categoryMap, services, serviceMap);

// Save the bundles
await this.saveBundles(bundles, serviceMap);
}

/**
* Save the services generating a map that stores human assigned ID to
* MongoDB IDs.
*
* Allowed connections and categories are add in later
*/
async saveServices(services: ServiceInput[]): Promise<Map<string, ObjectId>> {
const serviceMap = new Map<string, ObjectId>();
for (const service of services) {
const result = await this.serviceModel.create({
name: service.name,
icon: service.icon,
parameters: service.parameters,
allowedConnections: [],
result: service.result,
description: service.description,
resultParams: service.resultParams
resultParams: service.resultParams,
paramGroups: service.paramGroups
});

Check warning on line 65 in src/reset/reset.service.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

// Update the map
serviceMap.set(service.id, result._id);
Expand Down
4 changes: 4 additions & 0 deletions src/services/models/damplab-service.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@
*/
@Schema()
@ObjectType({ description: 'Services supported by the DampLab' })
export class DampLabService {
@Field(() => ID, { description: 'unique database generated ID', name: 'id' })
_id: string;

@Prop()
@Field({ description: 'Human readable name of the service' })
name: string;

@Prop()
@Field({ description: 'URL to the icon of the service' })
icon: string;

@Prop({ type: mongoose.Schema.Types.Mixed })
@Field(() => JSON, { description: 'Parameters that are part of the service' })
parameters: any;

@Prop({ type: mongoose.Schema.Types.Mixed, required: false })
@Field(() => JSON, { description: 'If there are grouped parameters', nullable: true })

Check warning on line 33 in src/services/models/damplab-service.model.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 33 in src/services/models/damplab-service.model.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
paramGroups: any[];

Check warning on line 34 in src/services/models/damplab-service.model.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

@Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: DampLabService.name }] })
@Field(() => [DampLabService], { description: 'List of services this service can connect to' })
allowedConnections: mongoose.Types.ObjectId[];
Expand Down
Loading