usr db #43
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
/*.json
|
||||
/db
|
||||
/log
|
||||
|
13
cli/start.zsh
Normal file
13
cli/start.zsh
Normal file
@ -0,0 +1,13 @@
|
||||
mkdir -p db
|
||||
rm -rf log; mkdir log
|
||||
|
||||
if systemctl > /dev/null; then
|
||||
cp -f mongod.service /lib/systemd/system/
|
||||
systemctl daemon-reload
|
||||
systemctl start mongod
|
||||
else
|
||||
nohup mongod --config mongod.yaml > log/mongod.log &
|
||||
fi
|
||||
|
||||
echo "\nismism started\n"
|
||||
pgrep -lf mongo
|
4
cli/stop.zsh
Normal file
4
cli/stop.zsh
Normal file
@ -0,0 +1,4 @@
|
||||
mongosh --eval "db.shutdownServer()"
|
||||
|
||||
echo "\nismism stopped\n"
|
||||
pgrep -lf mongo
|
1
ismism.ts/.vscode/tasks.json
vendored
1
ismism.ts/.vscode/tasks.json
vendored
@ -4,6 +4,7 @@
|
||||
{
|
||||
"type": "deno",
|
||||
"command": "test",
|
||||
"args": ["--allow-net"],
|
||||
"problemMatcher": [
|
||||
"$deno-test"
|
||||
],
|
||||
|
73
ismism.ts/deno.lock
generated
73
ismism.ts/deno.lock
generated
@ -1,12 +1,83 @@
|
||||
{
|
||||
"version": "2",
|
||||
"remote": {
|
||||
"https://deno.land/std@0.154.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
|
||||
"https://deno.land/std@0.154.0/_wasm_crypto/lib/deno_std_wasm_crypto.generated.mjs": "dfcd6777d05345362c70f9f2c49abba3ed3f925fccfcf725abe2d16d51819433",
|
||||
"https://deno.land/std@0.154.0/_wasm_crypto/mod.ts": "6c60d332716147ded0eece0861780678d51b560f533b27db2e15c64a4ef83665",
|
||||
"https://deno.land/std@0.154.0/async/deferred.ts": "c01de44b9192359cebd3fe93273fcebf9e95110bf3360023917da9a2d1489fae",
|
||||
"https://deno.land/std@0.154.0/bytes/bytes_list.ts": "aba5e2369e77d426b10af1de0dcc4531acecec27f9b9056f4f7bfbf8ac147ab4",
|
||||
"https://deno.land/std@0.154.0/bytes/equals.ts": "3c3558c3ae85526f84510aa2b48ab2ad7bdd899e2e0f5b7a8ffc85acb3a6043a",
|
||||
"https://deno.land/std@0.154.0/bytes/mod.ts": "763f97d33051cc3f28af1a688dfe2830841192a9fea0cbaa55f927b49d49d0bf",
|
||||
"https://deno.land/std@0.154.0/crypto/_fnv/fnv32.ts": "aa9bddead8c6345087d3abd4ef35fb9655622afc333fc41fff382b36e64280b5",
|
||||
"https://deno.land/std@0.154.0/crypto/_fnv/fnv64.ts": "625d7e7505b6cb2e9801b5fd6ed0a89256bac12b2bbb3e4664b85a88b0ec5bef",
|
||||
"https://deno.land/std@0.154.0/crypto/_fnv/index.ts": "a8f6a361b4c6d54e5e89c16098f99b6962a1dd6ad1307dbc97fa1ecac5d7060a",
|
||||
"https://deno.land/std@0.154.0/crypto/_fnv/util.ts": "4848313bed7f00f55be3cb080aa0583fc007812ba965b03e4009665bde614ce3",
|
||||
"https://deno.land/std@0.154.0/crypto/keystack.ts": "e481eed28007395e554a435e880fee83a5c73b9259ed8a135a75e4b1e4f381f7",
|
||||
"https://deno.land/std@0.154.0/crypto/mod.ts": "0ef11f063cd0f9759485a3c9051e15125e1bde3b47c23b47e79b6e13cfcf9481",
|
||||
"https://deno.land/std@0.154.0/crypto/timing_safe_equal.ts": "82a29b737bc8932d75d7a20c404136089d5d23629e94ba14efa98a8cc066c73e",
|
||||
"https://deno.land/std@0.154.0/encoding/base64.ts": "c57868ca7fa2fbe919f57f88a623ad34e3d970d675bdc1ff3a9d02bba7409db2",
|
||||
"https://deno.land/std@0.154.0/encoding/base64url.ts": "a5f82a9fa703bd85a5eb8e7c1296bc6529e601ebd9642cc2b5eaa6b38fa9e05a",
|
||||
"https://deno.land/std@0.154.0/encoding/hex.ts": "4cc5324417cbb4ac9b828453d35aed45b9cc29506fad658f1f138d981ae33795",
|
||||
"https://deno.land/std@0.154.0/fmt/colors.ts": "ff7dc9c9f33a72bd48bc24b21bbc1b4545d8494a431f17894dbc5fe92a938fc4",
|
||||
"https://deno.land/std@0.154.0/io/buffer.ts": "fae02290f52301c4e0188670e730cd902f9307fb732d79c4aa14ebdc82497289",
|
||||
"https://deno.land/std@0.154.0/io/files.ts": "d199ef64e918a256320ba8d8d44ae91de87c9077df8f8d6cca013f1b9fbbe285",
|
||||
"https://deno.land/std@0.154.0/io/mod.ts": "33507cf2460ab67d0d90fb5749fa6fecb33897642b49d54a6bb1ac81e4768f69",
|
||||
"https://deno.land/std@0.154.0/io/readers.ts": "45847ad404afd2f605eae1cff193f223462bc55eeb9ae313c2f3db28aada0fd6",
|
||||
"https://deno.land/std@0.154.0/io/streams.ts": "988a19155b52161f0035ce539e2f1d12edbc4c389fa7633da832a64e6edbe1a0",
|
||||
"https://deno.land/std@0.154.0/io/types.d.ts": "0cae3a62da7a37043661746c65c021058bae020b54e50c0e774916e5d4baee43",
|
||||
"https://deno.land/std@0.154.0/io/util.ts": "078da53bba767bec0d45f7da44411f6dbf269e51ef7fcfea5e3714e04681c674",
|
||||
"https://deno.land/std@0.154.0/io/writers.ts": "2e1c63ffd0cfba411b1fd8374609abff9ea86187c9d4d885d42e6fc20325ef0e",
|
||||
"https://deno.land/std@0.154.0/streams/conversion.ts": "fc4eb76a14148c43f0b85e903a5a1526391aa40ed9434dc21e34f88304eb823e",
|
||||
"https://deno.land/std@0.154.0/testing/_diff.ts": "141f978a283defc367eeee3ff7b58aa8763cf7c8e0c585132eae614468e9d7b8",
|
||||
"https://deno.land/std@0.154.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832",
|
||||
"https://deno.land/std@0.154.0/testing/asserts.ts": "ac295f7fd22a7af107580e2475402a8c386cb1bf18bf837ae266ac0665786026",
|
||||
"https://deno.land/std@0.178.0/encoding/base64.ts": "7de04c2f8aeeb41453b09b186480be90f2ff357613b988e99fabb91d2eeceba1",
|
||||
"https://deno.land/std@0.178.0/encoding/base64url.ts": "3f1178f6446834457b16bfde8b559c1cd3481727fe384d3385e4a9995dc2d851",
|
||||
"https://deno.land/std@0.178.0/encoding/hex.ts": "50f8c95b52eae24395d3dfcb5ec1ced37c5fe7610ef6fffdcc8b0fdc38e3b32f",
|
||||
"https://deno.land/std@0.178.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471",
|
||||
"https://deno.land/std@0.178.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea",
|
||||
"https://deno.land/std@0.178.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7",
|
||||
"https://deno.land/std@0.178.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab"
|
||||
"https://deno.land/std@0.178.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab",
|
||||
"https://deno.land/x/mongo@v0.31.2/deps.ts": "1b53a32fbc115195d74ab78e7d21026ea4b6590e5b558b388017cc1a9b8181e6",
|
||||
"https://deno.land/x/mongo@v0.31.2/mod.ts": "0989f34d08c40440b8786140abdaf863e964e23df5d1a80e661d3d4170d9d21e",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/auth/base.ts": "7fe14cf0a63d6bbc4ba69a000a04b3b184d26842504d94652a6af2d0c9494944",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/auth/mod.ts": "b161611bd5be9e9d1b4497227c8ea93ad4daadcd98038c9e5a707bc5da7a25ca",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/auth/pbkdf2.ts": "1f1db192fd37869d118ab34780b64567ebcf0ad83a03ef28b3d740cae9adb47a",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/auth/scram.ts": "187db02e94e7e5423ec902e87d6839028770dca57830dca7f154dcd22a959c0f",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/auth/x509.ts": "a75b27c549707dd441434ae400a3e6a24da7fe7d4e0e80c9bb79dfc6426b651e",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/client.ts": "368cac10b3df3bfbc2dfba468d1bbd1332c359a643e0bb81a13d7220a58b43ff",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/cluster.ts": "cff69bf284a5c7fcaff231494f1ab56ca652e725e58622723e402fbb61448d0e",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/collection.ts": "840add0cd28f38e8036b8d56fab134f9cc5201be05579d431a90f5c2e5b7c24e",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/commands/aggregate.ts": "440906a670adb46edb36fd95573ffa83f192775108b621520be992165910e895",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/commands/find.ts": "5c3b750d8c82ce08d865a381bc71f600406cbc4912c4aa689238755579fb71f8",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/commands/list_indexes.ts": "d32a5120305d0547497026b4f5ab2ecc2f40ff7f44c405b99c2a0287765333f5",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/commands/update.ts": "cf352108a5dd34f0928c2196a432383d366b8ed292676c71358b9ecf1289418d",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/collection/mod.ts": "bd791a0b9b46be4365f88c54893584eadec2f8cd799db9eb05e0b5b4c8d72b8e",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/database.ts": "f8dfd72f824759b1970232f4f21b8d1c3a0ca0ca6495c1dba32061c50c07ffba",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/error.ts": "8180a822b0831a94a6a28815865b5b40e3996220684bea60fcb81b272ddd06eb",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/gridfs/bucket.ts": "a4452d63f6928f57486a214a499b54b80b98cc0d13e3d85a6841b34d5ff12a61",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/gridfs/indexes.ts": "7d302114fb4d81c4a873614a51d11ddb8b471f967179dddb8269c39b3cadf4e3",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/gridfs/upload.ts": "6a54a21b00c6f22ad0da6ceef7a2932dc600560f594c2551abd8e4a64976abae",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/cursor.ts": "c370a28856fa236129cc2d7abf7ebc4ac6cdd60acb93e0e7371433f7332394cb",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/handshake.ts": "3c3ba547d5322751b9756ce9a4750f3cf18febee0a64edca5b007634bd80e0fe",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/header.ts": "0f28db842f886e57b7013606c1391affab2e2960a1a4568d2502e7b788117716",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/message.ts": "b1121b98420c9a44783619c7a0b2f7bb2cb305dfc64adc3e6a9b7781f4d35a3a",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/mod.ts": "4e24d563049c0a236234598ca786ca13778dc17fdb80ac543ac6c75d0c5094d7",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/protocol/protocol.ts": "92568dd86e6ef3f54054113d9f5620f158fc1dfee2a7c9d13623975835d5996a",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/types.ts": "c6b36e1751323b9eacee86372ba31715fe8e372d48b73a7c1ef69431c7a35b97",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/types/geojson.ts": "14690e2fa1591939253ddc9de181b0664051e9462db131b72be5fb9d064dff44",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/types/geospatial.ts": "c73ee13536365fa5d868b65ab47b3488a5f223a67e1e059761886f750db70ef9",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/types/gridfs.ts": "e1fd12c3ca58d437267e7a8557d745d23b9d8916d1da34c1847e5e373728dfa0",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/types/read_write_concern.ts": "d00f35eb85520e776741888685d08d479766a19e9a0a970b53f4594c9db00496",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/ns.ts": "fb0c57b8dc4d31f8993112d267dec3c163d3e8862198d1cd03b2b51bcc3caad9",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/saslprep/deps.ts": "95ceb81b353110526dacf2a98854bc79d6e17d7f173af8806e91c05555d7b8c7",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/saslprep/load_code_points.ts": "f6a4ef2eb2345eac40ffbf1a30661cca803f399865f2a0fadafb71f57d4c97bf",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/saslprep/memory_pager.ts": "f55a79a13ec569c21630c3915a9af0c6fc0aa2b899121fa2a85a813c6dd4afba",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/saslprep/mod.ts": "0a8a39a0784d065a79c54ce63d7d7b103d0b94addc5b7bcf985517ba2442c8a1",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/saslprep/sparse_bitfield.ts": "07d6fe2ecd4ba5f711c44c1ae409bb9c1fe3a3cfc09e27434d231d4aae46dd2d",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/srv.ts": "ed5f78ffe6480faac68291a87e51e3674eff5f28aec937ee97248e99e1317b16",
|
||||
"https://deno.land/x/mongo@v0.31.2/src/utils/uri.ts": "dcfab8e1dcfcc875c75ada1d9f366664480c03b65594990d6342ed88925452e5",
|
||||
"https://deno.land/x/web_bson@v0.3.0/mod.d.ts": "2e52e7b61cc0225d21c82c2ac74126c3f9af3c8002a54e094ea17b3cc7e599bc",
|
||||
"https://deno.land/x/web_bson@v0.3.0/mod.js": "8e14aecd31ee63abd30e2dbaa284b4b67abb7ba51fcef5b96af74727cb7c7940"
|
||||
}
|
||||
}
|
||||
|
@ -12,49 +12,6 @@ export type DocD = Promise<0 | 1 | null>
|
||||
const conn = new MongoClient()
|
||||
await conn.connect("mongodb://127.0.0.1:27017")
|
||||
|
||||
export let coll = await db("tst", true)
|
||||
|
||||
export async function db(
|
||||
dbnam: "ismism-dev" | "tst",
|
||||
reset = false,
|
||||
) {
|
||||
const db = conn.database(dbnam)
|
||||
const c = {
|
||||
usr: db.collection<Usr>("usr"),
|
||||
agd: db.collection<Agd>("agd"),
|
||||
soc: db.collection<Soc>("soc"),
|
||||
|
||||
work: db.collection<Work>("work"),
|
||||
video: db.collection<Video>("video"),
|
||||
ord: db.collection<Ord>("ord"),
|
||||
dst: db.collection<Dst>("dst"),
|
||||
|
||||
wsl: db.collection<Wsl>("wsl"),
|
||||
lit: db.collection<Lit>("lit"),
|
||||
|
||||
aut: db.collection<Aut>("aut"),
|
||||
act: db.collection<Act>("act"),
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
await db.dropDatabase()
|
||||
await c.usr.createIndexes({ indexes: [...nam, ...nbr, ...re] })
|
||||
await c.agd.createIndexes({ indexes: [...nam, ...adm, ...re, ...rel] })
|
||||
await c.soc.createIndexes({ indexes: [...nam, ...adm, ...re, ...rel] })
|
||||
|
||||
await c.work.createIndexes({ indexes: [...rec] })
|
||||
await c.video.createIndexes({ indexes: [...rec, ...live] })
|
||||
await c.ord.createIndexes({ indexes: [...rec] })
|
||||
await c.dst.createIndexes({ indexes: [...dst] })
|
||||
|
||||
await c.wsl.createIndexes({ indexes: [...md] })
|
||||
await c.lit.createIndexes({ indexes: [...md] })
|
||||
}
|
||||
|
||||
if (dbnam === "ismism-dev") coll = c
|
||||
return c
|
||||
}
|
||||
|
||||
const nam: IndexOptions[] = [{
|
||||
key: { nam: 1 }, name: "nam", unique: true,
|
||||
}]
|
||||
@ -100,3 +57,46 @@ const md: IndexOptions[] = [{
|
||||
key: { pin: 1, "utc.put": -1 }, name: "pin",
|
||||
partialFilterExpression: { pin: { $exists: true } }
|
||||
}]
|
||||
|
||||
export async function db(
|
||||
dbnam: "ismism-dev" | "tst",
|
||||
reset = false,
|
||||
) {
|
||||
const db = conn.database(dbnam)
|
||||
const c = {
|
||||
usr: db.collection<Usr>("usr"),
|
||||
agd: db.collection<Agd>("agd"),
|
||||
soc: db.collection<Soc>("soc"),
|
||||
|
||||
work: db.collection<Work>("work"),
|
||||
video: db.collection<Video>("video"),
|
||||
ord: db.collection<Ord>("ord"),
|
||||
dst: db.collection<Dst>("dst"),
|
||||
|
||||
wsl: db.collection<Wsl>("wsl"),
|
||||
lit: db.collection<Lit>("lit"),
|
||||
|
||||
aut: db.collection<Aut>("aut"),
|
||||
act: db.collection<Act>("act"),
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
await db.dropDatabase()
|
||||
await c.usr.createIndexes({ indexes: [...nam, ...nbr, ...re] })
|
||||
await c.agd.createIndexes({ indexes: [...nam, ...adm, ...re, ...rel] })
|
||||
await c.soc.createIndexes({ indexes: [...nam, ...adm, ...re, ...rel] })
|
||||
|
||||
await c.work.createIndexes({ indexes: [...rec] })
|
||||
await c.video.createIndexes({ indexes: [...rec, ...live] })
|
||||
await c.ord.createIndexes({ indexes: [...rec] })
|
||||
await c.dst.createIndexes({ indexes: [...dst] })
|
||||
|
||||
await c.wsl.createIndexes({ indexes: [...md] })
|
||||
await c.lit.createIndexes({ indexes: [...md] })
|
||||
}
|
||||
|
||||
if (dbnam === "ismism-dev") coll = c
|
||||
return c
|
||||
}
|
||||
|
||||
export let coll = await db("tst", true)
|
||||
|
@ -47,7 +47,7 @@ export async function id_u<
|
||||
u: Update<T>,
|
||||
): DocU {
|
||||
if (!is_id(_id)) return null
|
||||
const s = u["$set"]
|
||||
const s = u.$set
|
||||
if (s) {
|
||||
if (s.nam && !is_nam(s.nam)) return null
|
||||
if ((s.adm1 || s.adm2) && !((s.adm1 && s.adm2) && is_adm(s.adm1, s.adm2))) return null
|
||||
|
@ -58,6 +58,11 @@ export function is_nam(
|
||||
) {
|
||||
return typeof nam === "string" && /^[\u4E00-\u9FFF]{2,16}$/.test(nam)
|
||||
}
|
||||
export function is_nbr(
|
||||
nbr: string
|
||||
) {
|
||||
return typeof nbr === "string" && /^1\d{10}$/.test(nbr)
|
||||
}
|
||||
export function is_intro(
|
||||
intro: Id["intro"]
|
||||
) {
|
||||
@ -77,7 +82,7 @@ export function is_src(
|
||||
export function is_itm(
|
||||
itm: Itm
|
||||
) {
|
||||
return Object.keys(itm).length === 3 && is_nam(itm.nam) && itm.rmb >= 0 && itm.amt >= 0
|
||||
return Object.keys(itm).length === 4 && is_nam(itm.nam) && itm.rmb >= 0 && itm.amt >= 0 && is_msg(itm.msg)
|
||||
}
|
||||
export function is_loc(
|
||||
loc: Mnu["loc"][0]
|
||||
@ -92,6 +97,7 @@ export function is_mnu(
|
||||
&& Object.keys(mnu.utc).length === 2 && mnu.utc.end >= mnu.utc.start
|
||||
&& Object.keys(mnu.lim).length === 3 && mnu.lim.amt >= 0 && mnu.lim.sum >= 0 && mnu.lim.week >= 0
|
||||
&& mnu.itm.every(is_itm) && mnu.loc.every(is_loc)
|
||||
&& new Set(mnu.itm.map(t => t.nam)).size === mnu.itm.length
|
||||
}
|
||||
export function is_acc(
|
||||
acc: Agd["acc"]
|
||||
|
@ -19,6 +19,7 @@ export type Itm = {
|
||||
nam: string,
|
||||
rmb: number,
|
||||
amt: number,
|
||||
msg: string,
|
||||
}
|
||||
export type Mnu = {
|
||||
nam: string,
|
||||
@ -55,6 +56,7 @@ export type Video = Rec & Re & {
|
||||
export type Ord = Rec & {
|
||||
nam: string,
|
||||
itm: Itm[],
|
||||
msg: "",
|
||||
fin: boolean,
|
||||
rev?: { uid: Usr["_id"][], mrk: number, msg: string },
|
||||
loc?: Mnu["loc"][0],
|
||||
|
45
ismism.ts/src/eid/usr.ts
Normal file
45
ismism.ts/src/eid/usr.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import type { Usr } from "./typ.ts"
|
||||
import { DocC, DocD, DocR, DocU, Proj, Update, coll } from "./db.ts"
|
||||
import { is_lim, is_nbr, lim_code, lim_jwt } from "./is.ts"
|
||||
import { id_c, id_d, id_n, id_r, id_u } from "./id.ts"
|
||||
|
||||
export async function usr_c(
|
||||
nbr: NonNullable<Usr["nbr"]>,
|
||||
adm1: Usr["adm1"],
|
||||
adm2: Usr["adm2"],
|
||||
): DocC<Usr["_id"]> {
|
||||
if (!is_nbr(nbr)) return null
|
||||
const _id = await id_n(coll.usr)
|
||||
return id_c(coll.usr, {
|
||||
_id, utc: Date.now(), nam: `${_id}`,
|
||||
nbr, adm1, adm2, intro: "",
|
||||
})
|
||||
}
|
||||
|
||||
export async function usr_r<
|
||||
P extends keyof Usr
|
||||
>(
|
||||
f: Pick<Usr, "_id"> | Pick<Usr, "nam"> | { nbr: NonNullable<Usr["nbr"]> },
|
||||
p: Proj<Usr, P>,
|
||||
): DocR<Pick<Usr, "_id" | P>> {
|
||||
if ("nbr" in f && !is_nbr(f.nbr)) return null
|
||||
return await id_r(coll.usr, f, p)
|
||||
}
|
||||
|
||||
export async function usr_u(
|
||||
_id: Usr["_id"],
|
||||
u: Update<Usr>,
|
||||
): DocU {
|
||||
const s = u.$set
|
||||
if (s?.nbr && !is_nbr(s.nbr)
|
||||
|| s?.sms && !is_lim(s.sms.code, lim_code)
|
||||
|| s?.jwt && !is_lim(s.jwt.length, lim_jwt)
|
||||
) return null
|
||||
return await id_u(coll.usr, _id, u)
|
||||
}
|
||||
|
||||
export function usr_d(
|
||||
_id: Usr["_id"]
|
||||
): DocD {
|
||||
return id_d(coll.usr, _id)
|
||||
}
|
25
ismism.ts/tst/eid.test.ts
Normal file
25
ismism.ts/tst/eid.test.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { db } from "../src/eid/db.ts"
|
||||
import { usr_c, usr_d, usr_r, usr_u } from "../src/eid/usr.ts"
|
||||
import { assertEquals } from "./mod.ts"
|
||||
|
||||
await db("tst", true)
|
||||
|
||||
Deno.test("usr", async () => {
|
||||
const nbr = "11111111111"
|
||||
assertEquals(null, await usr_r({ _id: 1 }, { nbr: 1 }))
|
||||
const uid = await usr_c(nbr, "四川", "成都") as number
|
||||
assertEquals(1, uid)
|
||||
assertEquals({
|
||||
_id: uid, nam: `${uid}`, intro: "", adm2: "成都", nbr
|
||||
}, await usr_r(
|
||||
{ _id: uid }, { nam: 1, intro: 1, adm2: 1, nbr: 1 })
|
||||
)
|
||||
await usr_u(uid, { $set: { nam: "中文名", adm1: "广东", adm2: "汕头", rej: [2], intro: "介绍" } })
|
||||
assertEquals({
|
||||
_id: uid, nam: "中文名", adm2: "汕头", intro: "介绍"
|
||||
}, await usr_r(
|
||||
{ _id: uid }, { nam: 1, adm2: 1, intro: 1 })
|
||||
)
|
||||
assertEquals(1, await usr_d(uid))
|
||||
assertEquals(null, await usr_r({ _id: 1 }, { nbr: 1 }))
|
||||
})
|
31
mongod.service
Normal file
31
mongod.service
Normal file
@ -0,0 +1,31 @@
|
||||
Description=MongoDB Database Server
|
||||
Documentation=https://docs.mongodb.org/manual
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
EnvironmentFile=-/etc/default/mongod
|
||||
WorkingDirectory=/root/ismism
|
||||
ExecStart=mongod --config mongod.yaml
|
||||
PIDFile=/var/run/mongodb/mongod.pid
|
||||
# file size
|
||||
LimitFSIZE=infinity
|
||||
# cpu time
|
||||
LimitCPU=infinity
|
||||
# virtual memory size
|
||||
LimitAS=infinity
|
||||
# open files
|
||||
LimitNOFILE=64000
|
||||
# processes/threads
|
||||
LimitNPROC=64000
|
||||
# locked memory
|
||||
LimitMEMLOCK=infinity
|
||||
# total threads (user+kernel)
|
||||
TasksMax=infinity
|
||||
TasksAccounting=false
|
||||
|
||||
# Recommended limits for mongod as specified in
|
||||
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
10
mongod.yaml
Normal file
10
mongod.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
systemLog:
|
||||
destination: file
|
||||
path: log/mongo.log
|
||||
logAppend: false
|
||||
storage:
|
||||
dbPath: db
|
||||
net:
|
||||
bindIp: 127.0.0.1, ::1
|
||||
setParameter:
|
||||
notablescan: 1
|
Reference in New Issue
Block a user