Skip to content

Commit

Permalink
fix insert bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Oct 12, 2023
1 parent b0e5f91 commit 84561f4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/DboBuilder/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const isFile = (row: AnyObject) => {
export async function uploadFile(this: TableHandler, row: AnyObject, validate: ValidateRow | undefined, localParams: LocalParams | undefined, mediaId?: string): Promise<Media> {
if (!this.dboBuilder.prostgles?.fileManager) throw "fileManager not set up";

if (!isFile(row)) throw "Expecting only two properties for file upload: { name: string; data: File | string | Buffer }; but got: " + getKeys(row).map(k => `${k}: ${typeof data[k]}`).join(", ");
if (!isFile(row)) throw "Expecting only two properties for file upload: { name: string; data: File | string | Buffer }; but got: " + Object.entries(row).map(([k, v]) => `${k}: ${typeof v}`).join(", ");
const { data, name } = row;

const media_id = mediaId ?? (await this.db.oneOrNone("SELECT gen_random_uuid() as name")).name;
Expand Down
20 changes: 19 additions & 1 deletion lib/PublishParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,26 @@ export class PublishParser {
return _publish;
}
async getValidatedRequestRuleWusr({ tableName, command, localParams }: DboTableCommand): Promise<TableRule> {

const clientInfo = await this.prostgles.authHandler!.getClientInfo(localParams);
return await this.getValidatedRequestRule({ tableName, command, localParams }, clientInfo);
const rules = await this.getValidatedRequestRule({ tableName, command, localParams }, clientInfo);
/**
* Allow inserting into files table from a referencedColumn
*/
if(command === "insert" && localParams.nestedInsert){
const { referencingColumn, previousTable } = localParams.nestedInsert
const table = this.dbo[tableName];
const fileRef = this.prostgles.opts.fileTable?.referencedTables?.[previousTable];
if(table?.is_media && referencingColumn && isObject(fileRef) && isObject(fileRef.referenceColumns) && fileRef.referenceColumns[referencingColumn]){
return {
...rules,
insert: {
fields: "*"
},
}
}
}
return rules;
}

async getValidatedRequestRule({ tableName, command, localParams }: DboTableCommand, clientInfo?: AuthResult): Promise<TableRule> {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.1.86",
"version": "4.1.87",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/client/PID.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1754269
1782762
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 84561f4

Please sign in to comment.