25 lines
645 B
TypeScript
25 lines
645 B
TypeScript
import { DataSource } from 'typeorm';
|
|
import { PluginDataEntity } from '../../../entities';
|
|
import { GetPluginDataQuery } from '../../types';
|
|
|
|
export async function handleGetPluginData(query: GetPluginDataQuery, dataSource: DataSource): Promise<unknown> {
|
|
const { payload } = query;
|
|
const record = await dataSource.getRepository(PluginDataEntity).findOne({
|
|
where: {
|
|
key: payload.key,
|
|
pluginId: payload.pluginId,
|
|
scope: payload.scope,
|
|
serverId: payload.serverId ?? ''
|
|
}
|
|
});
|
|
|
|
if (!record) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
return JSON.parse(record.valueJson) as unknown;
|
|
} catch {
|
|
return null;
|
|
}
|
|
} |