This commit is contained in:
Simon Larsen 2023-10-03 13:54:55 +01:00
parent bbd57c917e
commit 36cbc22327
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 6 additions and 23 deletions

View File

@ -658,7 +658,7 @@ export default class AnalyticsDatabaseService<
return await this.onBeforeCreate(createBy);
}
public async create(createBy: CreateBy<TBaseModel>): Promise<void> {
public async create(createBy: CreateBy<TBaseModel>): Promise<TBaseModel> {
const onCreate: OnCreate<TBaseModel> = createBy.props.ignoreHooks
? { createBy, carryForward: [] }
: await this._onBeforeCreate(createBy);
@ -728,6 +728,9 @@ export default class AnalyticsDatabaseService<
);
}
}
return createBy.data;
} catch (error) {
await this.onCreateError(error as Exception);
throw this.getException(error as Exception);

View File

@ -1,4 +1,3 @@
import { JSONObject } from 'Common/Types/JSON';
import { Stream } from 'stream';
export default class StreamUtil {
@ -20,29 +19,10 @@ export default class StreamUtil {
});
}
public static async toJSONArray(
stream: Stream
): Promise<Array<JSONObject>> {
const text = await this.convertStreamToText(stream);
return JSON.parse(text);
}
public static async toStringArray(
stream: Stream
): Promise<Array<string>> {
return new Promise<Array<string>>(
(resolve: Function, reject: Function) => {
const data: Array<string> = [];
stream.on('data', (chunk: any) => {
data.push(chunk);
});
stream.on('end', () => {
resolve(data);
});
stream.on('error', (err: Error) => {
reject(err);
});
}
);
const text: string = await StreamUtil.convertStreamToText(stream);
return text.split('\n');
}
}