Do you think this object-oriented JavaScript (TypeScript) code is not well-written?
class KYC {
public reference;
public data = null;
constructor(id: string) {
this.reference = id ? firestoreAdmin.collection('kyc').doc(id) :
firestoreAdmin.collection('kyc').doc() :
}
async get() {
const result = await this.reference.get();
if(!result.exist) throw new Error('not found');
this.data = result.data;
return this;
}
static async getById(id: string) {
return await new this(id: string).get();
}
}
I structured it in this way because I feel that using new Kyc(id).get(); can be hard to read, particularly within an Express framework.
Is this approach considered bad practice or potentially an anti-pattern? Your thoughts are greatly appreciated!