मेरी समारोह getDocuments() में सारांश में होते हैं कि मैं पास कुछ मानकों की एक सरणी में (रास्ते की तरह, दस्तावेज़ का नाम, अगर मैं करने के लिए चाहते हैं अनुभाग द्वारा यह भागों) और पर आधारित है कि सरणी मैं वापस सामग्री के प्रत्येक दस्तावेज़ के माध्यम से एक पाश (ForOf), समारोह मैं यह कुछ भी से भी अधिक को बचाने के लिए मुझे भी कई लाइनों के कोड, समस्या यह है कि यह हमेशा मुझे फेंकता एक त्रुटि है कि मैं यह क्या है पता नहीं है.
आप मदद कर सकते हैं मुझे? कृपया
बादल समारोह
export const employees = functions.https.onRequest((request, response) => {
corsHandler(request, response, async () => {
return await security.securityLayer(
{ _definedMethod: "GET", userValue: request.method },
{ _definedType: true, _definedLevel: [4], _definedSeconds: 12, userToken: request.header("_token") },
{ required: false },
{ required: false }
).then(async (answer) => {
if (answer.status === 400 || answer.status === 401) {
return response.status(answer.status).send(answer);
}
return await security.getDocuments([
{ collection: "Core/", documentName: "Centers", options: { idReturn: "centros", nestedProperties: [] } },
{
collection: "Core/", documentName: "Employees", options: {
idReturn: "personal",
nestedProperties: [
{ idReturn: "employees", name: "employee" },
{ idReturn: "submanager", name: "submanager" },
{ idReturn: "manager", name: "manager" }
],
},
},
], SPECIAL_CODE).then((documents) => response.status(documents.status).send(documents))
.catch(() => response.status(500).send(security.error500(SPECIAL_CODE, 2)));
}).catch(() => response.status(500).send(security.error500("SPECIAL_CODE", 1)));
});
});
async समारोह
export async function getDocuments(
documents: {
collection: string,
documentName: string,
options: {
idReturn: string,
nestedProperties: {
idReturn: string,
name: string
}[]
}
}[],
code: string):
Promise<{ status: 201, code: string, subcode: number, devDescription: string, data: any }> {
const data: any = {};
const response: { devDescription: string, subcode: number } = { devDescription: "The document was found and retrieved successfully.", subcode: 1 };
if (documents.length > 1) {
response.devDescription = "Documents were found and obtained successfully.";
response.subcode = 2;
}
for (const iterator of documents) {
const docRef = { path: iterator.collection, name: iterator.documentName };
const options = { id: iterator.options.idReturn, nestedProperties: iterator.options.nestedProperties };
const doc = await database.collection(docRef.path).doc(docRef.name).get();
if (!doc.exists) {
data[options.id] = "The document " + docRef.name + " does not exist in the specified path: " + docRef.path;
if (documents.length === 1) {
response.devDescription = "The document was not found. Check the DATA for more information.";
response.subcode = 3;
} else {
response.devDescription = "One, several or all documents were not found. Check the DATA for more information.";
response.subcode = 3;
}
} else {
const docData: any = doc.data();
if (options.nestedProperties.length === 0) {
data[options.id] = docData;
} else {
for (const nested of options.nestedProperties) {
data[options.id][nested.idReturn] = _.get(docData, nested.name);
}
}
}
}
return { status: 201, code: code, subcode: response.subcode, devDescription: response.devDescription, data: data };
}