refactor: prevent update appName in services

This commit is contained in:
Mauricio Siu
2024-12-21 13:10:34 -06:00
parent 8e5b0988cf
commit 0abf62dd52
8 changed files with 16 additions and 16 deletions

View File

@@ -17,9 +17,9 @@ export const generateAppName = (type: string) => {
export const cleanAppName = (appName?: string) => {
if (!appName) {
return appName;
return appName?.toLowerCase();
}
return appName.trim().replace(/ /g, "-");
return appName.trim().replace(/ /g, "-").toLowerCase();
};
export const buildAppName = (type: string, baseAppName?: string) => {

View File

@@ -138,11 +138,11 @@ export const updateApplication = async (
applicationId: string,
applicationData: Partial<Application>,
) => {
const { appName, ...rest } = applicationData;
const application = await db
.update(applications)
.set({
...applicationData,
appName: cleanAppName(applicationData.appName),
...rest,
})
.where(eq(applications.applicationId, applicationId))
.returning();

View File

@@ -184,11 +184,11 @@ export const updateCompose = async (
composeId: string,
composeData: Partial<Compose>,
) => {
const { appName, ...rest } = composeData;
const composeResult = await db
.update(compose)
.set({
...composeData,
appName: cleanAppName(composeData.appName),
...rest,
})
.where(eq(compose.composeId, composeId))
.returning();

View File

@@ -80,11 +80,11 @@ export const updateMariadbById = async (
mariadbId: string,
mariadbData: Partial<Mariadb>,
) => {
const { appName, ...rest } = mariadbData;
const result = await db
.update(mariadb)
.set({
...mariadbData,
appName: cleanAppName(mariadbData.appName),
...rest,
})
.where(eq(mariadb.mariadbId, mariadbId))
.returning();

View File

@@ -72,11 +72,11 @@ export const updateMongoById = async (
mongoId: string,
mongoData: Partial<Mongo>,
) => {
const { appName, ...rest } = mongoData;
const result = await db
.update(mongo)
.set({
...mongoData,
appName: cleanAppName(mongoData.appName),
...rest,
})
.where(eq(mongo.mongoId, mongoId))
.returning();

View File

@@ -76,11 +76,11 @@ export const updateMySqlById = async (
mysqlId: string,
mysqlData: Partial<MySql>,
) => {
const { appName, ...rest } = mysqlData;
const result = await db
.update(mysql)
.set({
...mysqlData,
appName: cleanAppName(mysqlData.appName),
...rest,
})
.where(eq(mysql.mysqlId, mysqlId))
.returning();

View File

@@ -94,11 +94,11 @@ export const updatePostgresById = async (
postgresId: string,
postgresData: Partial<Postgres>,
) => {
const { appName, ...rest } = postgresData;
const result = await db
.update(postgres)
.set({
...postgresData,
appName: cleanAppName(postgresData.appName),
...rest,
})
.where(eq(postgres.postgresId, postgresId))
.returning();

View File

@@ -68,11 +68,11 @@ export const updateRedisById = async (
redisId: string,
redisData: Partial<Redis>,
) => {
const { appName, ...rest } = redisData;
const result = await db
.update(redis)
.set({
...redisData,
appName: cleanAppName(redisData.appName),
...rest,
})
.where(eq(redis.redisId, redisId))
.returning();