mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
30 lines
811 B
TypeScript
30 lines
811 B
TypeScript
import { Db } from '../../db/db';
|
|
import { IFeaturesReadModel } from './types/features-read-model-type';
|
|
|
|
export class FeaturesReadModel implements IFeaturesReadModel {
|
|
private db: Db;
|
|
|
|
constructor(db: Db) {
|
|
this.db = db;
|
|
}
|
|
|
|
async featureExists(parent: string): Promise<boolean> {
|
|
const rows = await this.db('features')
|
|
.where('name', parent)
|
|
.andWhere('archived_at', null)
|
|
.select('name');
|
|
|
|
return rows.length > 0;
|
|
}
|
|
|
|
async featuresInTheSameProject(
|
|
featureA: string,
|
|
featureB: string,
|
|
): Promise<boolean> {
|
|
const rows = await this.db('features')
|
|
.countDistinct('project as count')
|
|
.whereIn('name', [featureA, featureB]);
|
|
return Number(rows[0].count) === 1;
|
|
}
|
|
}
|