Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ const transformUser = (
*/
export const createUser = async (
username: string,
firstname: string,
lastname: string,
blockchainPublicKeys: Array<{ blockchain: Blockchain; publicKey: string }>,
waitlistId?: string | null,
referrerId?: string
Expand All @@ -324,11 +326,14 @@ export const createUser = async (
],
});

// zeus - automatically generated client for graphql
const response = await chain("mutation")({
insert_auth_users_one: [
{
object: {
username: username,
firstname: firstname,
lastname: lastname,
public_keys: {
data: blockchainPublicKeys.map((b) => ({
blockchain: b.blockchain,
Expand Down
5 changes: 4 additions & 1 deletion backend/native/backpack-api/src/routes/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ router.get("/jwt/xnft", extractUserId, async (req, res) => {
* Create a new user.
*/
router.post("/", async (req, res) => {
const { username, waitlistId, blockchainPublicKeys } =
console.log("Hi there...");
const { username, firstname, lastname, waitlistId, blockchainPublicKeys } =
CreateUserWithPublicKeys.parse(req.body);

// Validate all the signatures
Expand Down Expand Up @@ -182,6 +183,8 @@ router.post("/", async (req, res) => {

const user = await createUser(
username,
firstname,
lastname,
blockchainPublicKeys.map((b) => ({
...b,
// Cast blockchain to correct type
Expand Down
4 changes: 3 additions & 1 deletion backend/native/backpack-api/src/validation/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { ethers } from "ethers";
import { z } from "zod";

export const BaseCreateUser = z.object({
username: z
username: z.string(),
firstname: z.string(),
lastname: z
.string()
.regex(
/^[a-z0-9_]{3,15}$/,
Expand Down
1 change: 1 addition & 0 deletions backend/native/zeus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"graphql": "^16.8.1",
"tsc-alias": "^1.7.1",
"typescript": "~4.9.3"
},
Expand Down
37 changes: 27 additions & 10 deletions backend/native/zeus/src/zeus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const handleFetchResponse = (response: Response): Promise<GraphQLResponse> => {
.catch(reject);
});
}
return response.json();
return response.json() as Promise<GraphQLResponse>;
};

export const apiFetch =
Expand Down Expand Up @@ -362,12 +362,17 @@ export const traverseResponse = ({
) {
return o;
}
return Object.fromEntries(
Object.entries(o).map(([k, v]) => [
k,
ibb(k, v, [...p, purifyGraphQLKey(k)]),
])
const entries = Object.entries(o).map(
([k, v]) => [k, ibb(k, v, [...p, purifyGraphQLKey(k)])] as const
);
const objectFromEntries = entries.reduce<Record<string, unknown>>(
(a, [k, v]) => {
a[k] = v;
return a;
},
{}
);
return objectFromEntries;
};
return ibb;
};
Expand Down Expand Up @@ -759,8 +764,8 @@ export const resolverFor = <
source: any
) => Z extends keyof ModelTypes[T]
? ModelTypes[T][Z] | Promise<ModelTypes[T][Z]> | X
: any
) => fn as (args?: any, source?: any) => any;
: never
) => fn as (args?: any, source?: any) => ReturnType<typeof fn>;

export type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
export type ZeusState<T extends (...args: any[]) => Promise<any>> = NonNullable<
Expand Down Expand Up @@ -816,9 +821,13 @@ type IsInterfaced<
: DST[P],
SCLR
>
: Record<string, unknown>
: IsArray<
R,
"__typename" extends keyof DST ? { __typename: true } : never,
SCLR
>
: never;
}[keyof DST] & {
}[keyof SRC] & {
[P in keyof Omit<
Pick<
SRC,
Expand Down Expand Up @@ -4317,6 +4326,7 @@ export type ValueTypes = {
["auth_users_constraint"]: auth_users_constraint;
/** input type for inserting data into table "auth.users" */
["auth_users_insert_input"]: {
firstname?: string | undefined | null | Variable<any, string>;
invitation?:
| ValueTypes["auth_invitations_obj_rel_insert_input"]
| undefined
Expand All @@ -4327,6 +4337,7 @@ export type ValueTypes = {
| undefined
| null
| Variable<any, string>;
lastname?: string | undefined | null | Variable<any, string>;
public_keys?:
| ValueTypes["auth_public_keys_arr_rel_insert_input"]
| undefined
Expand Down Expand Up @@ -11097,11 +11108,13 @@ export type ResolverInputTypes = {
["auth_users_constraint"]: auth_users_constraint;
/** input type for inserting data into table "auth.users" */
["auth_users_insert_input"]: {
firstname?: string | undefined | null;
invitation?:
| ResolverInputTypes["auth_invitations_obj_rel_insert_input"]
| undefined
| null;
invitation_id?: ResolverInputTypes["uuid"] | undefined | null;
lastname?: string | undefined | null;
public_keys?:
| ResolverInputTypes["auth_public_keys_arr_rel_insert_input"]
| undefined
Expand Down Expand Up @@ -16048,10 +16061,12 @@ export type ModelTypes = {
["auth_users_constraint"]: auth_users_constraint;
/** input type for inserting data into table "auth.users" */
["auth_users_insert_input"]: {
firstname?: string | undefined;
invitation?:
| ModelTypes["auth_invitations_obj_rel_insert_input"]
| undefined;
invitation_id?: ModelTypes["uuid"] | undefined;
lastname?: string | undefined;
public_keys?:
| ModelTypes["auth_public_keys_arr_rel_insert_input"]
| undefined;
Expand Down Expand Up @@ -18949,10 +18964,12 @@ export type GraphQLTypes = {
["auth_users_constraint"]: auth_users_constraint;
/** input type for inserting data into table "auth.users" */
["auth_users_insert_input"]: {
firstname?: string | undefined;
invitation?:
| GraphQLTypes["auth_invitations_obj_rel_insert_input"]
| undefined;
invitation_id?: GraphQLTypes["uuid"] | undefined;
lastname?: string | undefined;
public_keys?:
| GraphQLTypes["auth_public_keys_arr_rel_insert_input"]
| undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ insert_permissions:
permission:
check: {}
columns:
- firstname
- invitation_id
- lastname
- referrer_id
- username
- waitlist_id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "auth"."users" add column "firstname" text
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "auth"."users" add column "firstname" text
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "auth"."users" add column "lastname" text
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "auth"."users" add column "lastname" text
null;
Loading