브랜드 설정 정규화 로직 분리
This commit is contained in:
48
lib/admin-brand-settings-section.js
Normal file
48
lib/admin-brand-settings-section.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
DEFAULT_BRAND_COLOR,
|
||||
normalizeBrandColor
|
||||
} from './brand-color.js'
|
||||
|
||||
export const BRAND_SETTINGS_FIELDS = ['brandColor']
|
||||
|
||||
/**
|
||||
* 브랜드 설정 기본 스냅샷을 만든다.
|
||||
* @returns {Object} 기본 브랜드 설정 값
|
||||
*/
|
||||
export const createDefaultBrandSettingsSnapshot = () => ({
|
||||
brandColor: DEFAULT_BRAND_COLOR
|
||||
})
|
||||
|
||||
/**
|
||||
* 브랜드 설정 값을 저장·비교 가능한 형태로 정규화한다.
|
||||
* @param {Object} source - 원본 설정 값
|
||||
* @returns {Object} 정규화된 브랜드 설정 값
|
||||
*/
|
||||
export const normalizeBrandSettingsSection = (source = {}) => ({
|
||||
brandColor: normalizeBrandColor(source.brandColor || DEFAULT_BRAND_COLOR)
|
||||
})
|
||||
|
||||
/**
|
||||
* 브랜드 설정 필드만 대상 객체에 복사한다.
|
||||
* @param {Object} target - 값을 받을 객체
|
||||
* @param {Object} source - 값을 제공할 객체
|
||||
* @returns {void}
|
||||
*/
|
||||
export const assignBrandSettingsSection = (target, source = {}) => {
|
||||
const normalized = normalizeBrandSettingsSection(source)
|
||||
BRAND_SETTINGS_FIELDS.forEach((field) => {
|
||||
target[field] = normalized[field]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 두 브랜드 설정 값이 다른지 확인한다.
|
||||
* @param {Object} current - 현재 설정 값
|
||||
* @param {Object} snapshot - 비교할 스냅샷
|
||||
* @returns {boolean} 변경 여부
|
||||
*/
|
||||
export const hasBrandSettingsSectionChanges = (current, snapshot) => {
|
||||
const normalizedCurrent = normalizeBrandSettingsSection(current)
|
||||
const normalizedSnapshot = normalizeBrandSettingsSection(snapshot)
|
||||
return BRAND_SETTINGS_FIELDS.some((field) => normalizedCurrent[field] !== normalizedSnapshot[field])
|
||||
}
|
||||
Reference in New Issue
Block a user