fixed assets uploading issue
This commit is contained in:
parent
11b230f9dd
commit
cc5dbee5be
@ -51,6 +51,7 @@ interface GenericDbFindAndCountOptions {
|
|||||||
|
|
||||||
type FieldTransformer = (value: unknown) => unknown;
|
type FieldTransformer = (value: unknown) => unknown;
|
||||||
type RelationSetter = (
|
type RelationSetter = (
|
||||||
|
this: EntityRecord,
|
||||||
value: unknown,
|
value: unknown,
|
||||||
options: { transaction?: Transaction | undefined },
|
options: { transaction?: Transaction | undefined },
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
@ -322,7 +323,8 @@ class GenericDBApi {
|
|||||||
if (data[assoc.field] !== undefined) {
|
if (data[assoc.field] !== undefined) {
|
||||||
const setter = record[assoc.setter];
|
const setter = record[assoc.setter];
|
||||||
if (isRelationSetter(setter)) {
|
if (isRelationSetter(setter)) {
|
||||||
await setter(
|
await setter.call(
|
||||||
|
record,
|
||||||
data[assoc.field] || (assoc.isArray ? [] : null),
|
data[assoc.field] || (assoc.isArray ? [] : null),
|
||||||
buildTransactionOptions(transaction),
|
buildTransactionOptions(transaction),
|
||||||
);
|
);
|
||||||
@ -393,7 +395,11 @@ class GenericDBApi {
|
|||||||
if (data[assoc.field] !== undefined) {
|
if (data[assoc.field] !== undefined) {
|
||||||
const setter = record[assoc.setter];
|
const setter = record[assoc.setter];
|
||||||
if (isRelationSetter(setter)) {
|
if (isRelationSetter(setter)) {
|
||||||
await setter(data[assoc.field], buildTransactionOptions(transaction));
|
await setter.call(
|
||||||
|
record,
|
||||||
|
data[assoc.field],
|
||||||
|
buildTransactionOptions(transaction),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -431,11 +431,21 @@ function getServerPort(): number {
|
|||||||
|
|
||||||
const PORT = getServerPort();
|
const PORT = getServerPort();
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
const server = app.listen(PORT, () => {
|
||||||
logger.info(
|
logger.info(
|
||||||
{ port: PORT, env: process.env.NODE_ENV || 'development' },
|
{ port: PORT, env: process.env.NODE_ENV || 'development' },
|
||||||
'Server started',
|
'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;
|
export default app;
|
||||||
|
|||||||
@ -51,6 +51,7 @@ interface UpdateContractCalls {
|
|||||||
serviceCreate?: unknown;
|
serviceCreate?: unknown;
|
||||||
serviceDeleteByIds?: unknown;
|
serviceDeleteByIds?: unknown;
|
||||||
serviceRemove?: unknown;
|
serviceRemove?: unknown;
|
||||||
|
associationThis?: TestAssociationRecord;
|
||||||
committed?: true;
|
committed?: true;
|
||||||
rolledBack?: true;
|
rolledBack?: true;
|
||||||
commits?: number;
|
commits?: number;
|
||||||
@ -139,7 +140,8 @@ void test('GenericDBApi.update uses object signature and forwards update context
|
|||||||
calls.update = { payload, options };
|
calls.update = { payload, options };
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
setTags(value, options) {
|
setTags(this: TestAssociationRecord, value, options) {
|
||||||
|
calls.associationThis = this;
|
||||||
calls.setTags = { value, options };
|
calls.setTags = { value, options };
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
@ -185,6 +187,7 @@ void test('GenericDBApi.update uses object signature and forwards update context
|
|||||||
value: ['a', 'b'],
|
value: ['a', 'b'],
|
||||||
options: {},
|
options: {},
|
||||||
});
|
});
|
||||||
|
assert.equal(calls.associationThis, record);
|
||||||
});
|
});
|
||||||
|
|
||||||
void test('GenericDBApi.update rejects positional signature', async () => {
|
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 () => {
|
void test('GenericDBApi.create rejects positional signature', async () => {
|
||||||
class TestDBApi extends GenericDBApi {
|
class TestDBApi extends GenericDBApi {
|
||||||
static override get MODEL(): unknown {
|
static override get MODEL(): unknown {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user