fixed assets uploading issue

This commit is contained in:
Dmitri 2026-07-01 18:52:43 +02:00
parent 11b230f9dd
commit cc5dbee5be
3 changed files with 66 additions and 4 deletions

View File

@ -51,6 +51,7 @@ interface GenericDbFindAndCountOptions {
type FieldTransformer = (value: unknown) => unknown;
type RelationSetter = (
this: EntityRecord,
value: unknown,
options: { transaction?: Transaction | undefined },
) => Promise<void>;
@ -322,7 +323,8 @@ class GenericDBApi {
if (data[assoc.field] !== undefined) {
const setter = record[assoc.setter];
if (isRelationSetter(setter)) {
await setter(
await setter.call(
record,
data[assoc.field] || (assoc.isArray ? [] : null),
buildTransactionOptions(transaction),
);
@ -393,7 +395,11 @@ class GenericDBApi {
if (data[assoc.field] !== undefined) {
const setter = record[assoc.setter];
if (isRelationSetter(setter)) {
await setter(data[assoc.field], buildTransactionOptions(transaction));
await setter.call(
record,
data[assoc.field],
buildTransactionOptions(transaction),
);
}
}
}

View File

@ -431,11 +431,21 @@ function getServerPort(): number {
const PORT = getServerPort();
app.listen(PORT, () => {
const server = app.listen(PORT, () => {
logger.info(
{ port: PORT, env: process.env.NODE_ENV || 'development' },
'Server started',
);
});
server.on('error', (err: NodeJS.ErrnoException) => {
logger.error(
{ err, port: PORT, env: process.env.NODE_ENV || 'development' },
'Server failed to start',
);
setImmediate(() => {
process.exit(1);
});
});
export default app;

View File

@ -51,6 +51,7 @@ interface UpdateContractCalls {
serviceCreate?: unknown;
serviceDeleteByIds?: unknown;
serviceRemove?: unknown;
associationThis?: TestAssociationRecord;
committed?: true;
rolledBack?: true;
commits?: number;
@ -139,7 +140,8 @@ void test('GenericDBApi.update uses object signature and forwards update context
calls.update = { payload, options };
return Promise.resolve();
},
setTags(value, options) {
setTags(this: TestAssociationRecord, value, options) {
calls.associationThis = this;
calls.setTags = { value, options };
return Promise.resolve();
},
@ -185,6 +187,7 @@ void test('GenericDBApi.update uses object signature and forwards update context
value: ['a', 'b'],
options: {},
});
assert.equal(calls.associationThis, record);
});
void test('GenericDBApi.update rejects positional signature', async () => {
@ -256,6 +259,49 @@ void test('GenericDBApi.create uses object signature and forwards create context
});
});
void test('GenericDBApi.create calls association setters with record context', async () => {
const calls: UpdateContractCalls = {};
const record: TestAssociationRecord = {
id: 'record-1',
update() {
return Promise.resolve();
},
setTags(this: TestAssociationRecord, value, options) {
calls.associationThis = this;
calls.setTags = { value, options };
return Promise.resolve();
},
};
class TestDBApi extends GenericDBApi {
static override get MODEL(): unknown {
return {
rawAttributes: {},
getTableName: () => 'test_records',
create(payload: DbData, options: TestTransactionOptions) {
calls.create = { payload, options };
return Promise.resolve(record);
},
};
}
static override get ASSOCIATIONS() {
return [{ field: 'tags', setter: 'setTags', isArray: true }];
}
}
await TestDBApi.create({
data: { name: 'Created', tags: ['a'] },
currentUser: createCurrentUser(),
});
assert.equal(calls.associationThis, record);
assert.deepEqual(calls.setTags, {
value: ['a'],
options: {},
});
});
void test('GenericDBApi.create rejects positional signature', async () => {
class TestDBApi extends GenericDBApi {
static override get MODEL(): unknown {