Open saurav-commits opened 11 months ago
for "fieldSetRepo" i get undefined help me with resolve it
import 'reflect-metadata'; import { Request } from 'express'; import Container, { Service, Inject } from 'typedi'; import { Repository, getRepository } from 'typeorm'; import { IResponse } from '@interfaces'; import { success } from '@utils/common.util'; import { FieldSettings } from '@models/field-settings.model'; import { InjectRepository } from 'typeorm-typedi-extensions';
@Service() class FieldSettingsController {
@InjectRepository(FieldSettings) private fieldSetRepo: Repository<FieldSettings>; private constructor() { // Private constructor to enforce singleton pattern } static getInstance(): FieldSettingsController { if (!FieldSettingsController.instance) { FieldSettingsController.instance = new FieldSettingsController(); } return FieldSettingsController.instance; } private static instance: FieldSettingsController; createFields = async (req: Request, res: IResponse): Promise<void> => { try { const fields = new FieldSettings({ name: req.body.name }); if (!this.fieldSetRepo) { throw new Error('Repository not initialized'); } await this.fieldSetRepo.save(fields); res.status(200).json(success('', {}, res.statusCode)); } catch (err) { console.error('Error:', err.message); res.status(400).json(success('', {}, res.statusCode)); } }; getAllFields = async (req: Request, res: IResponse): Promise<void> => { try { const fields = await this.fieldSetRepo.find(); res.status(200).json(success('', {fields}, res.statusCode)); } catch (err) { console.log('err', err); res.status(400).json(success('', {}, res.statusCode)); } } // ... other methods ...
}
const fieldSettingsController = FieldSettingsController.getInstance(); export { fieldSettingsController as FieldSettingsController };
for "fieldSetRepo" i get undefined help me with resolve it
import 'reflect-metadata'; import { Request } from 'express'; import Container, { Service, Inject } from 'typedi'; import { Repository, getRepository } from 'typeorm'; import { IResponse } from '@interfaces'; import { success } from '@utils/common.util'; import { FieldSettings } from '@models/field-settings.model'; import { InjectRepository } from 'typeorm-typedi-extensions';
@Service() class FieldSettingsController {
}
const fieldSettingsController = FieldSettingsController.getInstance(); export { fieldSettingsController as FieldSettingsController };