2023-04-12 01:59:14 -07:00
|
|
|
import { Service } from 'typedi';
|
|
|
|
import { DataSource, Repository } from 'typeorm';
|
2023-07-19 06:59:49 -07:00
|
|
|
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
2023-04-12 01:59:14 -07:00
|
|
|
import { Settings } from '../entities/Settings';
|
2023-06-19 07:23:57 -07:00
|
|
|
import config from '@/config';
|
2023-04-12 01:59:14 -07:00
|
|
|
|
|
|
|
@Service()
|
|
|
|
export class SettingsRepository extends Repository<Settings> {
|
|
|
|
constructor(dataSource: DataSource) {
|
|
|
|
super(Settings, dataSource.manager);
|
|
|
|
}
|
2023-06-19 07:23:57 -07:00
|
|
|
|
2023-07-14 06:36:17 -07:00
|
|
|
async dismissBanner({ bannerName }: { bannerName: string }): Promise<{ success: boolean }> {
|
2023-07-19 06:59:49 -07:00
|
|
|
const key = 'ui.banners.dismissed';
|
|
|
|
const dismissedBannersSetting = await this.findOneBy({ key });
|
|
|
|
try {
|
|
|
|
let value: string;
|
|
|
|
if (dismissedBannersSetting) {
|
2023-07-14 06:36:17 -07:00
|
|
|
const dismissedBanners = JSON.parse(dismissedBannersSetting.value) as string[];
|
2023-07-19 06:59:49 -07:00
|
|
|
const updatedValue = [...new Set([...dismissedBanners, bannerName].sort())];
|
|
|
|
value = JSON.stringify(updatedValue);
|
|
|
|
await this.update({ key }, { value, loadOnStartup: true });
|
|
|
|
} else {
|
|
|
|
value = JSON.stringify([bannerName]);
|
|
|
|
await this.save({ key, value, loadOnStartup: true });
|
2023-07-14 06:36:17 -07:00
|
|
|
}
|
2023-07-19 06:59:49 -07:00
|
|
|
config.set(key, value);
|
|
|
|
return { success: true };
|
|
|
|
} catch (error) {
|
|
|
|
ErrorReporter.error(error);
|
2023-07-14 06:36:17 -07:00
|
|
|
}
|
|
|
|
return { success: false };
|
|
|
|
}
|
2023-04-12 01:59:14 -07:00
|
|
|
}
|