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); 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 const onCreate: OnCreate<TBaseModel> = createBy.props.ignoreHooks
? { createBy, carryForward: [] } ? { createBy, carryForward: [] }
: await this._onBeforeCreate(createBy); : await this._onBeforeCreate(createBy);
@ -728,6 +728,9 @@ export default class AnalyticsDatabaseService<
); );
} }
} }
return createBy.data;
} catch (error) { } catch (error) {
await this.onCreateError(error as Exception); await this.onCreateError(error as Exception);
throw this.getException(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'; import { Stream } from 'stream';
export default class StreamUtil { 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( public static async toStringArray(
stream: Stream stream: Stream
): Promise<Array<string>> { ): Promise<Array<string>> {
return new Promise<Array<string>>( const text: string = await StreamUtil.convertStreamToText(stream);
(resolve: Function, reject: Function) => { return text.split('\n');
const data: Array<string> = [];
stream.on('data', (chunk: any) => {
data.push(chunk);
});
stream.on('end', () => {
resolve(data);
});
stream.on('error', (err: Error) => {
reject(err);
});
}
);
} }
} }