ansa
ansa
CCConvex Community
Created by ansa on 11/17/2022 in #general
Helper Functions
awesome that works, thank you!!
21 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
Helper Functions
yes!
21 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
Helper Functions
i tried import { Auth } from "./_generated/server" but it didnt seem to work :/
21 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
Helper Functions
also, what's the best way to type these without typing them as "any"? we have one solution here:
export const getUser = async ({
db,
auth,
}: Parameters<
Parameters<typeof query>[0]
>[0]): Promise<Document<"users"> | null> => {
const identity = await auth.getUserIdentity();
if (!identity) {
throw new Error("Called getUser without authentication present");
}

return await db
.query("users")
.filter((q) => q.eq(q.field("tokenIdentifier"), identity.tokenIdentifier))
.first();
};
export const getUser = async ({
db,
auth,
}: Parameters<
Parameters<typeof query>[0]
>[0]): Promise<Document<"users"> | null> => {
const identity = await auth.getUserIdentity();
if (!identity) {
throw new Error("Called getUser without authentication present");
}

return await db
.query("users")
.filter((q) => q.eq(q.field("tokenIdentifier"), identity.tokenIdentifier))
.first();
};
21 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
Helper Functions
if we write our own function, like in the example, there's no atomicity guarantees right? so we shouldn't create such a function which queries then edits the db?
21 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
GenericId vs. Id
oh okay, got it!
5 replies
CCConvex Community
Created by ansa on 11/17/2022 in #general
GenericId vs. Id
so I should always be using Id? what's GenericId for?
5 replies
CCConvex Community
Created by ansa on 11/7/2022 in #general
Customizing the Auth0 Login Page
oh it's just a one time thing, gotcha! I thought you had to do it every time you run the app or something. thanks!
4 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
gotcha! thanks!
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
did this
const newSubmission = await db.get(subId);
if (newSubmission === null)
throw new Error("new submission should not be null!");
return newSubmission;
const newSubmission = await db.get(subId);
if (newSubmission === null)
throw new Error("new submission should not be null!");
return newSubmission;
let me know if there's a better fix! thanks!
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
though this should never return null, because I just put it in the db; I'm a bit new to typescript so I'm not super sure how to resolve this
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
ah so, then I get this...
Type 'null' is not assignable to type '{ _id: GenericId<"submissions">; _creationTime: number; user: GenericId<"users">; application: GenericId<"applications">; submitted: boolean; fields: Map<...>; }'.
Type 'null' is not assignable to type '{ _id: GenericId<"submissions">; _creationTime: number; user: GenericId<"users">; application: GenericId<"applications">; submitted: boolean; fields: Map<...>; }'.
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
if i create it using the parameters, I still won't have the creationtime..
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
oh nevermind, I see it-- I was reading the msg incorrectly! thanks
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
also, just wondering, how did you know that was the issue?
21 replies
CCConvex Community
Created by ansa on 10/20/2022 in #general
db.insert return type
oh i see! is there an easy way to get this query to return the submission document? or should i make a document using the parameters I passed into the db.insert?
21 replies