Skip to content

Commit 780d06b

Browse files
feat: implement admin settings page with dynamic selection list management and repository integration
1 parent cd77fc2 commit 780d06b

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

backend/src/modules/admin-settings/infrastructure/repositories/admin-settings.repository.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ export class AdminSettingsRepository {
2222
async updateSettings(
2323
settings: Partial<AdminSettings>,
2424
): Promise<AdminSettings> {
25-
const doc = await this.settingsModel
26-
.findOneAndUpdate({}, { $set: settings }, { new: true, upsert: true })
27-
.exec();
25+
let doc = await this.settingsModel.findOne().exec();
26+
if (!doc) {
27+
doc = new this.settingsModel({
28+
location: { address: '', latitude: 0, longitude: 0 },
29+
ownerInfo: { name: '', phoneNumber: '' },
30+
...settings,
31+
});
32+
await doc.save();
33+
} else {
34+
doc.set(settings);
35+
await doc.save();
36+
}
2837
return this.toDomain(doc);
2938
}
3039

frontend/src/pages/settings/settings.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class SettingsComponent implements OnInit {
126126
// --- CRUD for Selection Lists ---
127127

128128
addItem(type: SelectListType) {
129-
const newItem = 'New Item';
129+
const newItem = '';
130130
switch(type) {
131131
case 'gallery': this.galleryCategories.update(items => [...items, newItem]); break;
132132
case 'treatment': this.treatmentCategories.update(items => [...items, newItem]); break;

frontend/src/pages/settings/ui/selects-settings.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ export type SelectListType = 'gallery' | 'treatment' | 'silhouette' | 'fabric' |
7676
<input
7777
#input
7878
(blur)="onUpdate(type, $index, input.value)"
79+
(keyup.enter)="input.blur()"
7980
[value]="item"
80-
class="flex-1 px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm text-black focus:bg-white transition-all"
81+
placeholder="Enter category name..."
82+
class="flex-1 px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm text-black focus:bg-white focus:outline-none focus:ring-2 focus:ring-primary/50 transition-all"
8183
/>
8284
<button (click)="removeItem.emit({type, index: $index})" class="text-gray-400 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all">
8385
<span class="material-symbols-outlined text-lg">delete</span>
@@ -103,6 +105,11 @@ export class SelectsSettingsComponent {
103105
save = output<void>();
104106

105107
onUpdate(type: SelectListType, index: number, value: string) {
106-
this.updateItem.emit({ type, index, value });
108+
const trimmed = value.trim();
109+
if (!trimmed) {
110+
this.removeItem.emit({ type, index });
111+
return;
112+
}
113+
this.updateItem.emit({ type, index, value: trimmed });
107114
}
108115
}

0 commit comments

Comments
 (0)