@umituz/react-native-ai-creations 1.4.7 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -28,26 +28,14 @@ export class CreationsService extends BaseRepository {
|
|
|
28
28
|
if (!db) throw new Error("Firestore not initialized");
|
|
29
29
|
|
|
30
30
|
try {
|
|
31
|
-
// 1. Generate ID (by creating a doc ref?)
|
|
32
|
-
// Actually, we can just use a random ID or let firestore generate it.
|
|
33
|
-
// But we need the ID for storage path.
|
|
34
|
-
|
|
35
|
-
// We'll use a new doc ref to get an ID
|
|
36
|
-
// NOTE: We assume repository exposes a way to get collection or we construct it.
|
|
37
|
-
// Since repository is abstract, we might not have access to internal collection ref easily.
|
|
38
|
-
// Let's assume standard path for now or ask repository (if we expanded interface).
|
|
39
|
-
// A better way: The service generates an ID.
|
|
40
|
-
|
|
41
31
|
const creationId = generateUUID();
|
|
42
32
|
|
|
43
|
-
// 2. Upload Image
|
|
44
33
|
const imageUrl = await this.storageService.uploadCreationImage(
|
|
45
34
|
dto.userId,
|
|
46
35
|
creationId,
|
|
47
36
|
dto.imageUri
|
|
48
37
|
);
|
|
49
38
|
|
|
50
|
-
// 3. Save Metadata to Firestore
|
|
51
39
|
await this.repository.create(dto.userId, {
|
|
52
40
|
id: creationId,
|
|
53
41
|
uri: imageUrl,
|
|
@@ -64,4 +52,20 @@ export class CreationsService extends BaseRepository {
|
|
|
64
52
|
throw error;
|
|
65
53
|
}
|
|
66
54
|
}
|
|
55
|
+
|
|
56
|
+
async getCreation(userId: string, id: string): Promise<any> {
|
|
57
|
+
return this.repository.getById(userId, id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async updateCreation(
|
|
61
|
+
userId: string,
|
|
62
|
+
id: string,
|
|
63
|
+
updates: { metadata?: Record<string, any> },
|
|
64
|
+
): Promise<boolean> {
|
|
65
|
+
return this.repository.update(userId, id, updates);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async deleteCreation(userId: string, id: string): Promise<boolean> {
|
|
69
|
+
return this.repository.delete(userId, id);
|
|
70
|
+
}
|
|
67
71
|
}
|
|
@@ -7,7 +7,13 @@ import type { Creation } from "../entities/Creation";
|
|
|
7
7
|
|
|
8
8
|
export interface ICreationsRepository {
|
|
9
9
|
getAll(userId: string): Promise<Creation[]>;
|
|
10
|
+
getById(userId: string, id: string): Promise<Creation | null>;
|
|
10
11
|
create(userId: string, creation: Creation): Promise<void>;
|
|
12
|
+
update(
|
|
13
|
+
userId: string,
|
|
14
|
+
id: string,
|
|
15
|
+
updates: Partial<Creation>,
|
|
16
|
+
): Promise<boolean>;
|
|
11
17
|
delete(userId: string, creationId: string): Promise<boolean>;
|
|
12
18
|
updateShared(
|
|
13
19
|
userId: string,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
collection,
|
|
18
18
|
doc,
|
|
19
19
|
getDocs,
|
|
20
|
+
getDoc,
|
|
20
21
|
deleteDoc,
|
|
21
22
|
updateDoc,
|
|
22
23
|
query,
|
|
@@ -117,6 +118,34 @@ export class CreationsRepository
|
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
async getById(userId: string, id: string): Promise<Creation | null> {
|
|
122
|
+
if (__DEV__) {
|
|
123
|
+
console.log("[CreationsRepository] getById()", { userId, id });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const docRef = this.getDocRef(userId, id);
|
|
127
|
+
if (!docRef) return null;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const docSnap = await getDoc(docRef);
|
|
131
|
+
|
|
132
|
+
if (!docSnap.exists()) {
|
|
133
|
+
if (__DEV__) {
|
|
134
|
+
console.log("[CreationsRepository] Document not found");
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const data = docSnap.data() as CreationDocument;
|
|
140
|
+
return this.documentMapper(docSnap.id, data);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (__DEV__) {
|
|
143
|
+
console.error("[CreationsRepository] getById() ERROR", error);
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
120
149
|
async create(userId: string, creation: Creation): Promise<void> {
|
|
121
150
|
const docRef = this.getDocRef(userId, creation.id);
|
|
122
151
|
if (!docRef) throw new Error("Firestore not initialized");
|
|
@@ -133,6 +162,47 @@ export class CreationsRepository
|
|
|
133
162
|
await setDoc(docRef, data);
|
|
134
163
|
}
|
|
135
164
|
|
|
165
|
+
async update(
|
|
166
|
+
userId: string,
|
|
167
|
+
id: string,
|
|
168
|
+
updates: Partial<Creation>,
|
|
169
|
+
): Promise<boolean> {
|
|
170
|
+
if (__DEV__) {
|
|
171
|
+
console.log("[CreationsRepository] update()", { userId, id, updates });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const docRef = this.getDocRef(userId, id);
|
|
175
|
+
if (!docRef) return false;
|
|
176
|
+
|
|
177
|
+
try {
|
|
178
|
+
const updateData: Record<string, any> = {};
|
|
179
|
+
|
|
180
|
+
if (updates.metadata !== undefined) {
|
|
181
|
+
updateData.metadata = updates.metadata;
|
|
182
|
+
}
|
|
183
|
+
if (updates.isShared !== undefined) {
|
|
184
|
+
updateData.isShared = updates.isShared;
|
|
185
|
+
}
|
|
186
|
+
if (updates.uri !== undefined) {
|
|
187
|
+
updateData.uri = updates.uri;
|
|
188
|
+
}
|
|
189
|
+
if (updates.type !== undefined) {
|
|
190
|
+
updateData.type = updates.type;
|
|
191
|
+
}
|
|
192
|
+
if (updates.prompt !== undefined) {
|
|
193
|
+
updateData.prompt = updates.prompt;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
await updateDoc(docRef, updateData);
|
|
197
|
+
return true;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (__DEV__) {
|
|
200
|
+
console.error("[CreationsRepository] update() ERROR", error);
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
136
206
|
async delete(userId: string, creationId: string): Promise<boolean> {
|
|
137
207
|
const docRef = this.getDocRef(userId, creationId);
|
|
138
208
|
if (!docRef) return false;
|