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) => { export const cleanAppName = (appName?: string) => {
if (!appName) { 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) => { export const buildAppName = (type: string, baseAppName?: string) => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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