Skip to content

Commit

Permalink
Merge pull request #155 from hemedani/main
Browse files Browse the repository at this point in the history
✨ add count document and some minor change
  • Loading branch information
hemedani authored Mar 21, 2024
2 parents 2a286a2 + 200473a commit b822116
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 278 deletions.
2 changes: 1 addition & 1 deletion pages/src/add_relation_fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const addUserLivedCity: ActFn = async (body) => {
const obIdLivedCities = livedCities.map((lc: string) => new ObjectId(lc));

return await users.addRelation({
_id: new ObjectId(_id),
filters: { _id: new ObjectId(_id) },
projection: body.details.get,
relations: {
livedCities: {
Expand Down
11 changes: 11 additions & 0 deletions src/odm/newModel/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { IPureFields, schemaFns, TSchemas } from "../../models/mod.ts";
import {
BulkWriteOptions,
CountDocumentsOptions,
Db,
DeleteOptions,
Document,
Expand Down Expand Up @@ -259,5 +260,15 @@ export const newModel = <
options,
projection,
}),

countDocument: (
{
filter,
options,
}: {
filter?: Document | undefined;
options?: CountDocumentsOptions | undefined;
},
) => db.collection(name).countDocuments(filter, options),
};
};
5 changes: 4 additions & 1 deletion src/odm/update/findOneAndUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ export const findOneAndUpdate = async <PureFields extends Document = Document>(
const relatedRelations = actualRel.relatedRelations;

if (actualRel.type === "single") {
if (updatedDocValue && updatedDocValue[rel]) {
if (
updatedDocValue && updatedDocValue[rel] &&
updatedDocValue[rel]._id
) {
const foundedActualRelSingleDoc = await db.collection(
actualRel.schemaName,
).findOne({ _id: updatedDocValue[rel]._id });
Expand Down
202 changes: 99 additions & 103 deletions src/server/playground/comp/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
value: 0 | 1 | null,
keyname: string,
getObj: Record<string, any>,
returnObj: Record<string, any>
returnObj: Record<string, any>,
) => {
for (const key in getObj) {
getObj[key].type === "enums"
? (returnObj[`${keyname}.${key}`] = value)
: changeGetValue(
value,
`${keyname}.${key}`,
getObj[key].schema,
returnObj
);
value,
`${keyname}.${key}`,
getObj[key].schema,
returnObj,
);
}
return returnObj;
};
Expand Down Expand Up @@ -123,7 +123,8 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
});
localStorage.setItem("localTabsData", JSON.stringify(tabsData));
}}
></MultiSelect>
>
</MultiSelect>
);
} else if (field["type"] === "enums") {
return (
Expand Down Expand Up @@ -280,7 +281,7 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
setTimeout(() => {
setSendLoading(false);
}, 450);
const tookTime = t1 - t0;
const tookTime = (t1 - t0).toFixed(2);

/* event.target.reset(); */
/* setFormData({}); */
Expand All @@ -305,8 +306,7 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
localStorage.setItem("localTabsData", JSON.stringify(tabsData));
};

const canShowRequestFields =
tabsData[activeTab].service &&
const canShowRequestFields = tabsData[activeTab].service &&
tabsData[activeTab].schema &&
tabsData[activeTab].postFields &&
tabsData[activeTab].getFields &&
Expand Down Expand Up @@ -343,7 +343,7 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {

const onClickItem = (
item: string,
type: "service" | "method" | "schema" | "action"
type: "service" | "method" | "schema" | "action",
) => {
if (type === "service") {
setService({
Expand Down Expand Up @@ -392,9 +392,9 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
<Selected
onClickItem={(item: string) => onClickItem(item, "service")}
items={Object.keys(actsObj)}
incomeActiveItem={
tabsData[activeTab].service ? tabsData[activeTab].service : null
}
incomeActiveItem={tabsData[activeTab].service
? tabsData[activeTab].service
: null}
/>
</div>

Expand All @@ -408,14 +408,12 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
<Selected
canShow={!canShowSchema}
onClickItem={(item: string) => onClickItem(item, "schema")}
items={
canShowSchema
? Object.keys((actsObj as any)[tabsData[activeTab].service])
: []
}
incomeActiveItem={
tabsData[activeTab].schema ? tabsData[activeTab].schema : null
}
items={canShowSchema
? Object.keys((actsObj as any)[tabsData[activeTab].service])
: []}
incomeActiveItem={tabsData[activeTab].schema
? tabsData[activeTab].schema
: null}
/>
</div>

Expand All @@ -424,18 +422,16 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
<Selected
canShow={!canShowAct}
onClickItem={(item: string) => onClickItem(item, "action")}
items={
canShowAct
? Object.keys(
(actsObj as any)[tabsData[activeTab].service][
tabsData[activeTab].schema
]
)
: []
}
incomeActiveItem={
tabsData[activeTab].act ? tabsData[activeTab].act : null
}
items={canShowAct
? Object.keys(
(actsObj as any)[tabsData[activeTab].service][
tabsData[activeTab].schema
],
)
: []}
incomeActiveItem={tabsData[activeTab].act
? tabsData[activeTab].act
: null}
/>
</div>
</div>
Expand Down Expand Up @@ -470,22 +466,23 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
null,
"get",
tabsData[activeTab].getFields,
{}
{},
);

setFormData({
data: { ...tabsData[activeTab].formData, ...copy },
index: activeTab,
});
}}
></span>
>
</span>
<span
onClick={() => {
const copy = changeGetValue(
0,
"get",
tabsData[activeTab].getFields,
{}
{},
);
setFormData({
data: {
Expand All @@ -504,7 +501,7 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
1,
"get",
tabsData[activeTab].getFields,
{}
{},
);
setFormData({
data: {
Expand All @@ -520,69 +517,70 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
</div>
</div>
{Object.keys(tabsData[activeTab].getFields).map((item) =>
tabsData[activeTab].getFields[item].type === "enums" ? (
<div
className="input-cnt get-items"
key={`${activeTab}.${item}-------`}
>
<label htmlFor={item}>{item}:</label>
<div className="get-values">
<span
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: null,
},
index: activeTab,
});
}}
></span>
<span
className={
tabsData[activeTab].formData[`get.${item}`] === 0
tabsData[activeTab].getFields[item].type === "enums"
? (
<div
className="input-cnt get-items"
key={`${activeTab}.${item}-------`}
>
<label htmlFor={item}>{item}:</label>
<div className="get-values">
<span
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: null,
},
index: activeTab,
});
}}
>
</span>
<span
className={tabsData[activeTab]
.formData[`get.${item}`] === 0
? "active"
: ""
}
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: 0,
},
index: activeTab,
});
}}
>
0
</span>
<span
className={
tabsData[activeTab].formData[`get.${item}`] === 1
: ""}
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: 0,
},
index: activeTab,
});
}}
>
0
</span>
<span
className={tabsData[activeTab]
.formData[`get.${item}`] === 1
? "active"
: ""
}
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: 1,
},
index: activeTab,
});
}}
>
1
</span>
: ""}
onClick={() => {
setFormData({
data: {
...tabsData[activeTab].formData,
[`get.${item}`]: 1,
},
index: activeTab,
});
}}
>
1
</span>
</div>
</div>
</div>
) : (
renderGetFields({
getField: tabsData[activeTab].getFields[item],
keyName: item,
margin: 0,
})
)
)
: (
renderGetFields({
getField: tabsData[activeTab].getFields[item],
keyName: item,
margin: 0,
})
)
)}
<div class="wrapper">
<button
Expand Down Expand Up @@ -649,11 +647,9 @@ export const Main = ({ urlAddress }: { urlAddress: string }) => {
{ConvertMilliseconds(tabsData[activeTab].response?.tookTime!)}
</span>
{tabsData[activeTab].response &&
tabsData[activeTab].response?.success === true ? (
<div className="success"></div>
) : (
<div className="fail"></div>
)}
tabsData[activeTab].response?.success === true
? <div className="success"></div>
: <div className="fail"></div>}
</div>
</div>
)}
Expand Down
Loading

0 comments on commit b822116

Please sign in to comment.