chore(server): standardize server db names and columns (#7674)

This commit is contained in:
forehalo
2024-07-31 07:59:22 +00:00
parent c6d4985cba
commit 4ec89ebd69
15 changed files with 276 additions and 459 deletions

View File

@@ -32,7 +32,7 @@ export async function getFeature(prisma: PrismaTransaction, featureId: number) {
return cachedFeature;
}
const feature = await prisma.features.findFirst({
const feature = await prisma.feature.findFirst({
where: {
id: featureId,
},

View File

@@ -10,7 +10,7 @@ export class FeatureService {
constructor(private readonly prisma: PrismaClient) {}
async getFeature<F extends FeatureType>(feature: F) {
const data = await this.prisma.features.findFirst({
const data = await this.prisma.feature.findFirst({
where: {
feature,
type: FeatureKind.Feature,
@@ -36,7 +36,7 @@ export class FeatureService {
expiredAt?: Date | string
) {
return this.prisma.$transaction(async tx => {
const latestFlag = await tx.userFeatures.findFirst({
const latestFlag = await tx.userFeature.findFirst({
where: {
userId,
feature: {
@@ -53,7 +53,7 @@ export class FeatureService {
if (latestFlag) {
return latestFlag.id;
} else {
const featureId = await tx.features
const featureId = await tx.feature
.findFirst({
where: { feature, type: FeatureKind.Feature },
orderBy: { version: 'desc' },
@@ -65,7 +65,7 @@ export class FeatureService {
throw new Error(`Feature ${feature} not found`);
}
return tx.userFeatures
return tx.userFeature
.create({
data: {
reason,
@@ -81,7 +81,7 @@ export class FeatureService {
}
async removeUserFeature(userId: string, feature: FeatureType) {
return this.prisma.userFeatures
return this.prisma.userFeature
.updateMany({
where: {
userId,
@@ -104,7 +104,7 @@ export class FeatureService {
* @returns list of features
*/
async getUserFeatures(userId: string) {
const features = await this.prisma.userFeatures.findMany({
const features = await this.prisma.userFeature.findMany({
where: {
userId,
feature: { type: FeatureKind.Feature },
@@ -129,7 +129,7 @@ export class FeatureService {
}
async getActivatedUserFeatures(userId: string) {
const features = await this.prisma.userFeatures.findMany({
const features = await this.prisma.userFeature.findMany({
where: {
userId,
feature: { type: FeatureKind.Feature },
@@ -156,7 +156,7 @@ export class FeatureService {
}
async listFeatureUsers(feature: FeatureType) {
return this.prisma.userFeatures
return this.prisma.userFeature
.findMany({
where: {
activated: true,
@@ -182,7 +182,7 @@ export class FeatureService {
}
async hasUserFeature(userId: string, feature: FeatureType) {
return this.prisma.userFeatures
return this.prisma.userFeature
.count({
where: {
userId,
@@ -206,7 +206,7 @@ export class FeatureService {
expiredAt?: Date | string
) {
return this.prisma.$transaction(async tx => {
const latestFlag = await tx.workspaceFeatures.findFirst({
const latestFlag = await tx.workspaceFeature.findFirst({
where: {
workspaceId,
feature: {
@@ -223,7 +223,7 @@ export class FeatureService {
return latestFlag.id;
} else {
// use latest version of feature
const featureId = await tx.features
const featureId = await tx.feature
.findFirst({
where: { feature, type: FeatureKind.Feature },
select: { id: true },
@@ -235,7 +235,7 @@ export class FeatureService {
throw new Error(`Feature ${feature} not found`);
}
return tx.workspaceFeatures
return tx.workspaceFeature
.create({
data: {
reason,
@@ -251,7 +251,7 @@ export class FeatureService {
}
async removeWorkspaceFeature(workspaceId: string, feature: FeatureType) {
return this.prisma.workspaceFeatures
return this.prisma.workspaceFeature
.updateMany({
where: {
workspaceId,
@@ -274,7 +274,7 @@ export class FeatureService {
* @returns list of features
*/
async getWorkspaceFeatures(workspaceId: string) {
const features = await this.prisma.workspaceFeatures.findMany({
const features = await this.prisma.workspaceFeature.findMany({
where: {
workspace: { id: workspaceId },
feature: {
@@ -301,7 +301,7 @@ export class FeatureService {
}
async listFeatureWorkspaces(feature: FeatureType): Promise<WorkspaceType[]> {
return this.prisma.workspaceFeatures
return this.prisma.workspaceFeature
.findMany({
where: {
activated: true,
@@ -324,7 +324,7 @@ export class FeatureService {
}
async hasWorkspaceFeature(workspaceId: string, feature: FeatureType) {
return this.prisma.workspaceFeatures
return this.prisma.workspaceFeature
.count({
where: {
workspaceId,