Skip to content

Commit

Permalink
Added toast component; profile read only form
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshschuler committed May 25, 2023
1 parent c5ed76e commit a7dd9cc
Show file tree
Hide file tree
Showing 33 changed files with 512 additions and 33 deletions.
121 changes: 121 additions & 0 deletions api/deps_lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"version": "2",
"remote": {
"https://deno.land/std@0.183.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462",
"https://deno.land/std@0.183.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3",
"https://deno.land/std@0.183.0/async/deferred.ts": "42790112f36a75a57db4a96d33974a936deb7b04d25c6084a9fa8a49f135def8",
"https://deno.land/std@0.183.0/bytes/bytes_list.ts": "31d664f4d42fa922066405d0e421c56da89d751886ee77bbe25a88bf0310c9d0",
"https://deno.land/std@0.183.0/bytes/concat.ts": "d26d6f3d7922e6d663dacfcd357563b7bf4a380ce5b9c2bbe0c8586662f25ce2",
"https://deno.land/std@0.183.0/bytes/copy.ts": "939d89e302a9761dcf1d9c937c7711174ed74c59eef40a1e4569a05c9de88219",
"https://deno.land/std@0.183.0/bytes/ends_with.ts": "4228811ebc71615d27f065c54b5e815ec1972538772b0f413c0efe05245b472e",
"https://deno.land/std@0.183.0/bytes/equals.ts": "b87494ce5442dc786db46f91378100028c402f83a14a2f7bbff6bda7810aefe3",
"https://deno.land/std@0.183.0/bytes/includes_needle.ts": "76a8163126fb2f8bf86fd7f22192c3bb04bf6a20b987a095127c2ca08adf3ba6",
"https://deno.land/std@0.183.0/bytes/index_of_needle.ts": "65c939607df609374c4415598fa4dad04a2f14c4d98cd15775216f0aaf597f24",
"https://deno.land/std@0.183.0/bytes/last_index_of_needle.ts": "7181072883cb4908c6ce8f7a5bb1d96787eef2c2ab3aa94fe4268ab326a53cbf",
"https://deno.land/std@0.183.0/bytes/mod.ts": "e869bba1e7a2e3a9cc6c2d55471888429a544e70a840c087672e656e7ba21815",
"https://deno.land/std@0.183.0/bytes/repeat.ts": "6f5e490d8d72bcbf8d84a6bb04690b9b3eb5822c5a11687bca73a2318a842294",
"https://deno.land/std@0.183.0/bytes/starts_with.ts": "3e607a70c9c09f5140b7a7f17a695221abcc7244d20af3eb47ccbb63f5885135",
"https://deno.land/std@0.183.0/crypto/keystack.ts": "877ab0f19eb7d37ad6495190d3c3e39f58e9c52e0b6a966f82fd6df67ca55f90",
"https://deno.land/std@0.183.0/crypto/timing_safe_equal.ts": "0fae34ee02264f309ae0b6e54e9746a7aba3996e5454903ed106967a7a9ef665",
"https://deno.land/std@0.183.0/encoding/base64.ts": "144ae6234c1fbe5b68666c711dc15b1e9ee2aef6d42b3b4345bf9a6c91d70d0d",
"https://deno.land/std@0.183.0/encoding/base64url.ts": "2ed4ba122b20fedf226c5d337cf22ee2024fa73a8f85d915d442af7e9ce1fae1",
"https://deno.land/std@0.183.0/http/_negotiation/common.ts": "14d1a52427ab258a4b7161cd80e1d8a207b7cc64b46e911780f57ead5f4323c6",
"https://deno.land/std@0.183.0/http/_negotiation/encoding.ts": "ff747d107277c88cb7a6a62a08eeb8d56dad91564cbcccb30694d5dc126dcc53",
"https://deno.land/std@0.183.0/http/_negotiation/language.ts": "7bcddd8db3330bdb7ce4fc00a213c5547c1968139864201efd67ef2d0d51887d",
"https://deno.land/std@0.183.0/http/_negotiation/media_type.ts": "58847517cd549384ad677c0fe89e0a4815be36fe7a303ea63cee5f6a1d7e1692",
"https://deno.land/std@0.183.0/http/cookie_map.ts": "d148a5eaf35f19905dd5104126fa47ac71105306dd42f129732365e43108b28a",
"https://deno.land/std@0.183.0/http/etag.ts": "4cb24b489e71c6bc333ab03b93edac303faddc199b3a6d0bfba284c8980a3dd2",
"https://deno.land/std@0.183.0/http/http_errors.ts": "b9a18ef97d6c5966964de95e04d1f9f88a0f8bd8577c26fd402d9d632fb03a42",
"https://deno.land/std@0.183.0/http/http_status.ts": "8a7bcfe3ac025199ad804075385e57f63d055b2aed539d943ccc277616d6f932",
"https://deno.land/std@0.183.0/http/negotiation.ts": "46e74a6bad4b857333a58dc5b50fe8e5a4d5267e97292293ea65f980bd918086",
"https://deno.land/std@0.183.0/http/server_sent_event.ts": "856764c8c058605bb618272833990b1f88b6de0dcc460f0f09749ba7e99dd656",
"https://deno.land/std@0.183.0/io/buf_reader.ts": "abeb92b18426f11d72b112518293a96aef2e6e55f80b84235e8971ac910affb5",
"https://deno.land/std@0.183.0/io/buf_writer.ts": "48c33c8f00b61dcbc7958706741cec8e59810bd307bc6a326cbd474fe8346dfd",
"https://deno.land/std@0.183.0/io/buffer.ts": "17f4410eaaa60a8a85733e8891349a619eadfbbe42e2f319283ce2b8f29723ab",
"https://deno.land/std@0.183.0/io/copy_n.ts": "0cc7ce07c75130f6fc18621ec1911c36e147eb9570664fee0ea12b1988167590",
"https://deno.land/std@0.183.0/io/limited_reader.ts": "6c9a216f8eef39c1ee2a6b37a29372c8fc63455b2eeb91f06d9646f8f759fc8b",
"https://deno.land/std@0.183.0/io/mod.ts": "2665bcccc1fd6e8627cca167c3e92aaecbd9897556b6f69e6d258070ef63fd9b",
"https://deno.land/std@0.183.0/io/multi_reader.ts": "9c2a0a31686c44b277e16da1d97b4686a986edcee48409b84be25eedbc39b271",
"https://deno.land/std@0.183.0/io/read_delim.ts": "c02b93cc546ae8caad8682ae270863e7ace6daec24c1eddd6faabc95a9d876a3",
"https://deno.land/std@0.183.0/io/read_int.ts": "7cb8bcdfaf1107586c3bacc583d11c64c060196cb070bb13ae8c2061404f911f",
"https://deno.land/std@0.183.0/io/read_lines.ts": "c526c12a20a9386dc910d500f9cdea43cba974e853397790bd146817a7eef8cc",
"https://deno.land/std@0.183.0/io/read_long.ts": "f0aaa420e3da1261c5d33c5e729f09922f3d9fa49f046258d4ff7a00d800c71e",
"https://deno.land/std@0.183.0/io/read_range.ts": "28152daf32e43dd9f7d41d8466852b0d18ad766cd5c4334c91fef6e1b3a74eb5",
"https://deno.land/std@0.183.0/io/read_short.ts": "805cb329574b850b84bf14a92c052c59b5977a492cd780c41df8ad40826c1a20",
"https://deno.land/std@0.183.0/io/read_string_delim.ts": "5dc9f53bdf78e7d4ee1e56b9b60352238ab236a71c3e3b2a713c3d78472a53ce",
"https://deno.land/std@0.183.0/io/slice_long_to_bytes.ts": "48d9bace92684e880e46aa4a2520fc3867f9d7ce212055f76ecc11b22f9644b7",
"https://deno.land/std@0.183.0/io/string_reader.ts": "da0f68251b3d5b5112485dfd4d1b1936135c9b4d921182a7edaf47f74c25cc8f",
"https://deno.land/std@0.183.0/io/string_writer.ts": "8a03c5858c24965a54c6538bed15f32a7c72f5704a12bda56f83a40e28e5433e",
"https://deno.land/std@0.183.0/media_types/_db.ts": "7606d83e31f23ce1a7968cbaee852810c2cf477903a095696cdc62eaab7ce570",
"https://deno.land/std@0.183.0/media_types/_util.ts": "916efbd30b6148a716f110e67a4db29d6949bf4048997b754415dd7e42c52378",
"https://deno.land/std@0.183.0/media_types/content_type.ts": "ad98a5aa2d95f5965b2796072284258710a25e520952376ed432b0937ce743bc",
"https://deno.land/std@0.183.0/media_types/extension.ts": "a7cd28c9417143387cdfed27d4e8607ebcf5b1ec27eb8473d5b000144689fe65",
"https://deno.land/std@0.183.0/media_types/extensions_by_type.ts": "43806d6a52a0d6d965ada9d20e60a982feb40bc7a82268178d94edb764694fed",
"https://deno.land/std@0.183.0/media_types/format_media_type.ts": "f5e1073c05526a6f5a516ac5c5587a1abd043bf1039c71cde1166aa4328c8baf",
"https://deno.land/std@0.183.0/media_types/get_charset.ts": "18b88274796fda5d353806bf409eb1d2ddb3f004eb4bd311662c4cdd8ac173db",
"https://deno.land/std@0.183.0/media_types/mod.ts": "d3f0b99f85053bc0b98ecc24eaa3546dfa09b856dc0bbaf60d8956d2cdd710c8",
"https://deno.land/std@0.183.0/media_types/parse_media_type.ts": "835c4112e1357e95b4f10d7cdea5ae1801967e444f48673ff8f1cb4d32af9920",
"https://deno.land/std@0.183.0/media_types/type_by_extension.ts": "daa801eb0f11cdf199445d0f1b656cf116d47dcf9e5b85cc1e6b4469f5ee0432",
"https://deno.land/std@0.183.0/media_types/vendor/mime-db.v1.52.0.ts": "6925bbcae81ca37241e3f55908d0505724358cda3384eaea707773b2c7e99586",
"https://deno.land/std@0.183.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0",
"https://deno.land/std@0.183.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b",
"https://deno.land/std@0.183.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0",
"https://deno.land/std@0.183.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000",
"https://deno.land/std@0.183.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1",
"https://deno.land/std@0.183.0/path/mod.ts": "bf718f19a4fdd545aee1b06409ca0805bd1b68ecf876605ce632e932fe54510c",
"https://deno.land/std@0.183.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d",
"https://deno.land/std@0.183.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1",
"https://deno.land/std@0.183.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba",
"https://deno.land/std@0.183.0/streams/_common.ts": "f45cba84f0d813de3326466095539602364a9ba521f804cc758f7a475cda692d",
"https://deno.land/std@0.183.0/streams/buffer.ts": "d5b3d7d0299114e5b2ea895a8bf202a687fd915c5282f8096c7bae23b5a04407",
"https://deno.land/std@0.183.0/streams/byte_slice_stream.ts": "225d57263a34325d7c96cb3dafeb478eec0e6fd05cd0458d678752eadd132bb4",
"https://deno.land/std@0.183.0/streams/copy.ts": "75cbc795ff89291df22ddca5252de88b2e16d40c85d02840593386a8a1454f71",
"https://deno.land/std@0.183.0/streams/delimiter_stream.ts": "f69e849b3d1f59f02424497273f411105a6f76a9f13da92aeeb9a2d554236814",
"https://deno.land/std@0.183.0/streams/early_zip_readable_streams.ts": "4005fa74162b943f79899e5d7cb96adcbc0a6b867f9144974ed12d30e0a556e1",
"https://deno.land/std@0.183.0/streams/iterate_reader.ts": "bbec1d45c2df2c0c5920bad0549351446fdc8e0886d99e95959b259dbcdb6072",
"https://deno.land/std@0.183.0/streams/limited_bytes_transform_stream.ts": "05dc592ffaab83257494d22dd53917e56243c26e5e3129b3f13ddbbbc4785048",
"https://deno.land/std@0.183.0/streams/limited_transform_stream.ts": "d69ab790232c1b86f53621ad41ef03c235f2abb4b7a1cd51960ad6e12ee55e38",
"https://deno.land/std@0.183.0/streams/merge_readable_streams.ts": "5d6302888f4bb0616dafb5768771be0aec9bedc05fbae6b3d726d05ffbec5b15",
"https://deno.land/std@0.183.0/streams/mod.ts": "c07ec010e700b9ea887dc36ca08729828bc7912f711e4054e24d33fd46282252",
"https://deno.land/std@0.183.0/streams/read_all.ts": "ee319772fb0fd28302f97343cc48dfcf948f154fd0d755d8efe65814b70533be",
"https://deno.land/std@0.183.0/streams/readable_stream_from_iterable.ts": "cd4bb9e9bf6dbe84c213beb1f5085c326624421671473e410cfaecad15f01865",
"https://deno.land/std@0.183.0/streams/readable_stream_from_reader.ts": "bfc416c4576a30aac6b9af22c9dc292c20c6742141ee7c55b5e85460beb0c54e",
"https://deno.land/std@0.183.0/streams/reader_from_iterable.ts": "55f68110dce3f8f2c87b834d95f153bc904257fc65175f9f2abe78455cb8047c",
"https://deno.land/std@0.183.0/streams/reader_from_stream_reader.ts": "fa4971e5615a010e49492c5d1688ca1a4d17472a41e98b498ab89a64ebd7ac73",
"https://deno.land/std@0.183.0/streams/text_delimiter_stream.ts": "20e680ab8b751390e359288ce764f9c47d164af11a263870746eeca4bc7d976b",
"https://deno.land/std@0.183.0/streams/text_line_stream.ts": "0f2c4b33a5fdb2476f2e060974cba1347cefe99a4af33c28a57524b1a34750fa",
"https://deno.land/std@0.183.0/streams/to_transform_stream.ts": "7f55fc0b14cf3ed0f8d10d8f41d05bdc40726e44a65c37f58705d10a615f0159",
"https://deno.land/std@0.183.0/streams/writable_stream_from_writer.ts": "56fff5c82fb736fdd669b567cc0b2bbbe0351002cd13254eae26c366e2bed89a",
"https://deno.land/std@0.183.0/streams/write_all.ts": "aec90152978581ea62d56bb53a5cbf487e6a89c902f87c5969681ffbdf32b998",
"https://deno.land/std@0.183.0/streams/writer_from_stream_writer.ts": "07c7ee025151a190f37fc42cbb01ff93afc949119ebddc6e0d0df14df1bf6950",
"https://deno.land/std@0.183.0/streams/zip_readable_streams.ts": "a9d81aa451240f79230add674809dbee038d93aabe286e2d9671e66591fc86ca",
"https://deno.land/std@0.183.0/types.d.ts": "dbaeb2c4d7c526db9828fc8df89d8aecf53b9ced72e0c4568f97ddd8cda616a4",
"https://deno.land/x/oak@v12.2.0/application.ts": "d7c712ce36ac5785179b534b055c229a667f4fd6090ec63a82338b94bd490181",
"https://deno.land/x/oak@v12.2.0/body.ts": "c7392f1dae04a360838f43b9cdd2f83d29c1eff4e6071d5f0cf1f3999b1602bc",
"https://deno.land/x/oak@v12.2.0/buf_reader.ts": "7cf96aa0ac670b75098113cf88a291a68332cc45efa8a9698f064ac5b8098a0f",
"https://deno.land/x/oak@v12.2.0/content_disposition.ts": "8b8c3cb2fba7138cd5b7f82fc3b5ea39b33db924a824b28261659db7e164621e",
"https://deno.land/x/oak@v12.2.0/context.ts": "8765e43b0438d4d56110152cadb25e066d378a07dc39db6daf3b9dfaee1e38ed",
"https://deno.land/x/oak@v12.2.0/deps.ts": "14d49d20d95e18b884bbe18d93b3cfa98b2be2bbc65ea24ec8fefbb2e6480b00",
"https://deno.land/x/oak@v12.2.0/etag.ts": "393cb69513b44058ea034571892ec6aa602ec50c45303a24c706d32ef57a3da4",
"https://deno.land/x/oak@v12.2.0/headers.ts": "f50fb05614432bda971021633129aa2e8737e0844e0f01c27a937997b4d8dd4f",
"https://deno.land/x/oak@v12.2.0/helpers.ts": "42212afa07a560b2958359cc19577417e89d9574d6579551a0af36ff7f00cc6e",
"https://deno.land/x/oak@v12.2.0/http_server_native.ts": "0141e1339ed9a33bc26ce537ddab5adbb3542b35916d92de286aed4937e4a6d6",
"https://deno.land/x/oak@v12.2.0/http_server_native_request.ts": "be315d476550e149c58d7ccd2812be30f373ceedc9c323c300eef03b7c071aa9",
"https://deno.land/x/oak@v12.2.0/isMediaType.ts": "62d638abcf837ece3a8f07a4b7ca59794135cb0d4b73194c7d5837efd4161005",
"https://deno.land/x/oak@v12.2.0/mediaTyper.ts": "042b853fc8e9c3f6c628dd389e03ef481552bf07242efc3f8a1af042102a6105",
"https://deno.land/x/oak@v12.2.0/middleware.ts": "de14f045a2ddfe845d89b5d3140ff52cbcc6f3b3965391106ce04480f9786737",
"https://deno.land/x/oak@v12.2.0/middleware/proxy.ts": "b927232f97ec18af4185d7912e45b1191e3ffe24a9c875262ad524211b1274c9",
"https://deno.land/x/oak@v12.2.0/mod.ts": "c3bb5eec0fa11cf6dc9e0bf3543564a4ee1f3d152ceb675b383a5ee5bc37ce15",
"https://deno.land/x/oak@v12.2.0/multipart.ts": "98fe9f226de8c26a16d067027b69fb1e34ad8c4055767dd157907d06cea36f9a",
"https://deno.land/x/oak@v12.2.0/range.ts": "68a6df7ab3b868843e33f52deb94c3d4cab25cb9ef369691990c2ac15b04fafb",
"https://deno.land/x/oak@v12.2.0/request.ts": "5852ad36389b48e0428a6f3c90854d01f10d1b15949b56001e1e75c2a00ef0f9",
"https://deno.land/x/oak@v12.2.0/response.ts": "867d81f7eb0c65c7b8e0e0e9e145ededd5b6daa9ad922e6adc6a36a525f439a6",
"https://deno.land/x/oak@v12.2.0/router.ts": "5b266091e55f634c9130e6de5dd331ddfc4c190ee7916a25e0a0f75502edbc32",
"https://deno.land/x/oak@v12.2.0/send.ts": "5ec49f106294593f468317a0c885da4f3274bf6d0fe9e16a7304391730b4f4fb",
"https://deno.land/x/oak@v12.2.0/structured_clone.ts": "9c2d21c62f616400305a60cbd29eb06764ee97edc423223424b6cf55df0e8be2",
"https://deno.land/x/oak@v12.2.0/testing.ts": "a0be5c84981afde666de29630f34b09d944ca1a2fe6a5185644b60ad95e16d18",
"https://deno.land/x/oak@v12.2.0/types.d.ts": "41951a18c3bfdb11e40707cab75da078ba8a4907cd7d4e11d8536bc2db0dde05",
"https://deno.land/x/oak@v12.2.0/util.ts": "3af8c4ed04c6cc2bedbe66e562a77fc59c72df31c55a902a63885861ca1639d6",
"https://deno.land/x/path_to_regexp@v6.2.1/index.ts": "894060567837bae8fc9c5cbd4d0a05e9024672083d5883b525c031eea940e556"
}
}
2 changes: 1 addition & 1 deletion api/import_map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"@/": "./src/",
"@prisma": "./prisma/mod.ts",
"prisma": "./prisma/mod.ts",
"oak": "https://deno.land/x/oak@v12.2.0/mod.ts",
"router": "https://deno.land/x/oak@v12.2.0/router.ts",
"helpers": "https://deno.land/x/oak@v12.2.0/helpers.ts"
Expand Down
4 changes: 3 additions & 1 deletion api/prisma/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const trainerWithAlts = Prisma.validator<Prisma.TrainerArgs>()({

export type TrainerWithAlts = Prisma.TrainerGetPayload<typeof trainerWithAlts>

export default prisma;
export {
prisma
};
10 changes: 10 additions & 0 deletions api/src/controllers/profile.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { syncProfile } from "@/handlers/commands/syncProfile.handler.ts";
import { getProfile } from "@/handlers/queries/getProfile.handler.ts";
import { ProfileResponse } from "@/types/profile.ts";
import { TrainerAltResponse } from "@/types/trainer.ts";
import { createResponse, handleResponse } from "@/utils/response.ts";
import { RouterContext } from "router";

Expand All @@ -19,6 +20,7 @@ async function get(ctx: RouterContext<string>) {
}

const { id, user_id, username, trainer } = profile!;

handleResponse(
ctx,
createResponse<ProfileResponse>({
Expand All @@ -27,6 +29,14 @@ async function get(ctx: RouterContext<string>) {
username,
trainerCode: trainer?.trainer_code,
trainerName: trainer?.trainer_name,
trainerAlts: trainer?.alts.map((alt) => {
return {
id: alt.id,
name: alt.alt_trainer_name,
code: alt.alt_trainer_code,
order: alt.order,
};
}) as TrainerAltResponse[],
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/trainers.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Status } from "@/deps.ts";
import { logError } from "@/handlers/commands/createLog.handler.ts";
import queries from "@/handlers/queries/index.ts";
import { SearchTrainersRequest } from "@/types/requests/searchTrainersRequest.ts";
import { handleResponse } from "@/utils/response.ts";
import { getQuery } from "helpers";
import { Status } from "oak";
import { RouterContext } from "router";

export async function searchTrainers(ctx: RouterContext<string>) {
Expand Down
2 changes: 2 additions & 0 deletions api/src/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Status } from "oak";
export { prisma, type TrainerWithAlts } from "prisma";
2 changes: 1 addition & 1 deletion api/src/handlers/commands/createLog.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prisma from "@prisma";
import { prisma } from "@/deps.ts";

export async function log(level: string, logType: string, message: string, meta?: any, requestId?: string) {
await prisma.log.create({
Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/commands/createProfile.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prisma } from "@/deps.ts";
import { MeResponse } from "@/types/response/meResponse.ts";
import prisma from "@prisma";

export async function createProfile(
me: MeResponse,
Expand Down
16 changes: 16 additions & 0 deletions api/src/handlers/commands/createTrainer.handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { prisma } from "@/deps.ts";

export async function createTrainer(username: string): Promise<number | undefined> {
const trainer = await prisma.trainer.create({
data: {
username,
trainer_code: "",
trainer_name: "",
},
select: {
id: true,
},
});

return trainer.id;
}
7 changes: 6 additions & 1 deletion api/src/handlers/commands/syncProfile.handler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { getTrainerByUsername } from "../queries/getTrainerByUsername.handler.ts";
import { createProfile } from "./createProfile.handler.ts";
import { createTrainer } from "./createTrainer.handler.ts";
import { getDiscordProfile } from "./getDiscordProfile.handler.ts";

export async function syncProfile(accessToken: string): Promise<string | null> {
const meResponse = await getDiscordProfile(accessToken!);

if (meResponse) {
const trainerId = await getTrainerByUsername(meResponse.username);
let trainerId = await getTrainerByUsername(meResponse.username);
if (!trainerId) {
trainerId = await createTrainer(meResponse.username);
}

return createProfile(meResponse, trainerId);
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/commands/syncTrainerCodes.handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prisma, TrainerWithAlts } from "@/deps.ts";
import { ApiResponse } from "@/types/common.ts";
import { TrainerRowData } from "@/types/models.ts";
import { SyncTrainersResponse } from "@/types/response/syncTrainersResponse.ts";
import prisma, { TrainerWithAlts } from "@prisma";
import { parse } from "https://deno.land/std@0.182.0/encoding/csv.ts";
import { TrainerAlt } from "../../../generated/client/deno/index.d.ts";

Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/queries/getProfile.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prisma } from "@/deps.ts";
import { ProfileWithRelatedEntities } from "@/types/profile.ts";
import prisma from "@prisma";

export async function getProfile(userId: string): Promise<ProfileWithRelatedEntities> {
const profile = await prisma.profile.findFirst({
Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/queries/getTrainerByUsername.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import prisma from "@prisma";
import { prisma } from "@/deps.ts";

export async function getTrainerByUsername(username: string): Promise<number | undefined> {
const trainer = await prisma.trainer.findFirst({
Expand Down
2 changes: 1 addition & 1 deletion api/src/handlers/queries/searchTrainers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prisma } from "@/deps.ts";
import { ApiResponse } from "@/types/common.ts";
import { SearchTrainersRequest } from "@/types/requests/searchTrainersRequest.ts";
import { SearchTrainersResponse, TrainerResponse } from "@/types/response/searchTrainersResponse.ts";
import prisma from "@prisma";
import { Trainer } from "../../../generated/client/deno/index.d.ts";

const defaultPageSize = 15;
Expand Down
2 changes: 2 additions & 0 deletions api/src/types/profile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Profile, Trainer, TrainerAlt } from "../../generated/client/deno/index.d.ts";
import { TrainerAltResponse } from "./trainer.ts";

export interface ProfileResponse {
profileId: number;
username: string;
userId: string;
trainerName?: string;
trainerCode?: string;
trainerAlts: TrainerAltResponse[];
}

export type ProfileWithTrainer = Profile & { trainer: Trainer | null } | null;
Expand Down
6 changes: 6 additions & 0 deletions api/src/types/trainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface TrainerAltResponse {
id: number;
name: string;
code: string;
order: number;
}
Loading

0 comments on commit a7dd9cc

Please sign in to comment.