hezarfen_backend
Clone
https://git.tahinli.com/archive/hezarfen_backend.git
0 watching0 forksRust8.3 MiB08aa13eAhmet Kaan Gümüş2 months ago378 commits
| 1 | //! The `work_entry` table: the open-slot check-in/check-out pair, the |
| 2 | //! newest-first log, and manager corrections guarded by the stored order. |
| 3 | |
| 4 | use SurrealValue; |
| 5 | |
| 6 | use crate; |
| 7 | use crateFieldUpdate; |
| 8 | use cratePagedList; |
| 9 | use crateTimestamp; |
| 10 | use crateUserId; |
| 11 | use crate; |
| 12 | use crateAppError; |
| 13 | |
| 14 | /// Open a stint for `user`, stamped with the server clock. `INSERT IGNORE` |
| 15 | /// on the deterministic open id makes this atomic: if an open entry |
| 16 | /// already exists the insert is skipped (empty result) and the caller gets |
| 17 | /// a conflict — two racing check-ins can never create two open rows or |
| 18 | /// reset a running clock. |
| 19 | pub async |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | /// Close `user`'s open stint: atomically take the open row and re-file it |
| 39 | /// under a ULID id, freeing the open slot for the next check-in. Take and |
| 40 | /// re-file share one transaction — a failed re-file rolls the take back, |
| 41 | /// so a stint can never vanish half-closed. Of two racing check-outs |
| 42 | /// exactly one receives the row (the other gets the conflict). |
| 43 | /// |
| 44 | /// A lost round is re-sent rather than reported (`transaction_with_retry`): |
| 45 | /// the abort wrote nothing, so the whole cascade is safe to repeat, and the |
| 46 | /// `CREATE` cannot answer "already exists" on the way back — the table |
| 47 | /// carries no `UNIQUE` index and `$closed` is one freshly minted ULID. |
| 48 | /// Only the guard's own `THROW` is a decision, and it stays a 409. |
| 49 | pub async |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | pub async |
| 93 | |
| 94 | |
| 95 | |
| 96 | /// Every stint of `user`, newest first — the open one (if any) included. |
| 97 | /// Ordered by `check_in`, never by id alone: the open entry's `open_` key |
| 98 | /// doesn't sort with the ULIDs, so id order would misplace it. The `id` |
| 99 | /// tie-break behind it only ever separates two *closed* stints sharing a |
| 100 | /// `check_in` — there is one open row per user, so it can never tie with |
| 101 | /// itself — and that is what keeps offset paging from skipping a row. |
| 102 | pub async |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | /// Persist corrected instants (manager fix-ups on closed entries; the web |
| 118 | /// layer validates ordering and rejects open entries). |
| 119 | /// `None` = the correction left that instant out, so it is not written at |
| 120 | /// all — the stint's `user` and `check_in`/`check_out` stamps are never |
| 121 | /// replayed from a struct the handler read before its validation awaits. |
| 122 | /// `check_out` is never cleared here: an open stint is refused upstream, so |
| 123 | /// "absent" and "null" both mean keep. |
| 124 | pub async |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | pub async |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 |