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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate records #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,13 @@ export default class Client {
}
return this._workflowExecutions;
}

get externalContributions() {
if (!this._externalContributions) {
// @ts-ignore
this._externalContributions = new ExternalContributionsApiClient(this.config.external_contributions_url, this.token);
}

return this._externalContributions;
}
}
41 changes: 24 additions & 17 deletions src/commands/duplicate-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@ interface Arguments extends CommandArguments {

const command = 'duplicate-records';
const description = 'Duplicate records into new app';
const builder: CommandBuilder = (yargs) => yargs
.option('source', {
required: true,
alias: 's',
type: 'string',
description: 'Form ID to pull records from',
})
.option('destination', {
required: true,
alias: 'd',
type: 'string',
description: 'Form ID to add records to',
})
.strict(false);
const builder = (yargs) => {
yargs
.option('origin', {
required: true,
alias: 'o',
type: 'string',
description: 'Form ID to pull records from',
})
.option('destination', {
required: true,
alias: 'd',
type: 'string',
description: 'Form ID to add records to',
})
.option('sql', {
alias: 'sql',
type: 'string',
description: 'SQL query',
})
.strict(false);
};

const handler: CommandHandler<Arguments> = async ({
endpoint, token, source, destination,
const handler = async ({
endpoint, token, origin, destination, sql,
}) => {
const client = createClient(endpoint, token);

await duplicateRecords(client, source, destination);
await duplicateRecords(client, origin, destination, sql);
};

export default defineCommand({
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

// @ts-nocheck
import path from 'path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
Expand Down
11 changes: 3 additions & 8 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function fetchHistoryRecords(client: Client, params: any) {
return records;
}

export async function fetchRecords(client: Client, params: any) {
export async function fetchRecords(client: Client, params: any): Promise<object[]> {
const perPage = 5000;
const records = [];

Expand Down Expand Up @@ -152,7 +152,7 @@ export async function fetchRecordsBySQL(
form: Core.Form,
sql: string,
where?: string,
) {
): Promise<Core.Record[]> {
console.log('fetching records by sql', sql, where);

const query = where ? `${sql} WHERE ${where}` : sql;
Expand Down Expand Up @@ -407,12 +407,7 @@ export async function download(url, outputFileName) {
});
}

export async function duplicateRecordsWithMedia(
client: Client,
records: Record[],
form: Form,
comment: string,
) {
export async function duplicateRecordsWithMedia(client: Client, records: Object[], form: Form, comment: string) {
const operations = [];

for (const attrs of records) {
Expand Down