Skip to content

Commit

Permalink
fix(arango): changes from new arangojs version
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Dec 12, 2024
1 parent 6fba187 commit 2aedabf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions oada/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@ USER root

COPY --from=dev /oada/ /oada/


# Default to a production target
FROM production
18 changes: 13 additions & 5 deletions oada/libs/lib-arangodb/src/libs/putBodies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,31 @@
import { config } from '../config.js';
import { db as database } from '../db.js';

const collection = database.collection(
const collection = database.collection<{body: unknown}>(
config.get('arangodb.collections.putBodies.name'),
);

/**
* Give string of JSON rather than object
*/
export async function savePutBody(body: string): Promise<{ _id: string }> {
// The _id comes back in the response to save
return collection.save({body});
// HACK: send body without parsing it
const cursor = await database.query<string>({
query: `
INSERT ${body}
INTO ${collection.name}
RETURN NEW._id
`,
bindVars: {},
});
return { _id: (await cursor.next())! };
}

export async function getPutBody(id: string): Promise<unknown> {
const { body } = (await collection.document(id)) as { body: unknown };
const { body } = await collection.document(id);
return body;
}

export async function removePutBody(id: string): Promise<void> {
await collection.remove(id);
}
}
4 changes: 2 additions & 2 deletions oada/services/http-handler/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {
const { _id: bodyid } = await putBodies.savePutBody(
request.body as string,
);
request.log.trace({ oadaGraph: request.oadaGraph }, 'PUT body saved');
request.log.debug({ oadaGraph: request.oadaGraph, bodyid }, 'PUT body saved');

request.log.trace('Resource exists: %s', request.resourceExists);
const ignoreLinks =
Expand Down Expand Up @@ -740,4 +740,4 @@ const plugin: FastifyPluginAsync<Options> = async (fastify, options) => {
});
};

export default plugin;
export default plugin;

0 comments on commit 2aedabf

Please sign in to comment.