Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Change firstname and lastname from settings #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
},
"hostRequirements": {
"cpus": 8,
"memory": "8gb",
"storage": "64gb"
}
}
44 changes: 44 additions & 0 deletions backend/native/backpack-api/src/db/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export const getUserByUsername = async (username: string) => {
{
id: true,
username: true,
firstname: true,
lastname: true,
public_keys: [
{},
{
Expand Down Expand Up @@ -212,6 +214,8 @@ export const getUser = async (id: string, onlyActiveKeys?: boolean) => {
{
id: true,
username: true,
firstname: true,
lastname: true,
public_keys: [
{},
{
Expand Down Expand Up @@ -251,6 +255,8 @@ const transformUsers = (
users: {
id: unknown;
username: unknown;
firstname: unknown;
lastname: unknown;
public_keys: Array<{
blockchain: string;
public_key: string;
Expand All @@ -268,6 +274,8 @@ const transformUser = (
user: {
id: unknown;
username: unknown;
firstname: unknown;
lastname: unknown;
public_keys: Array<{
blockchain: string;
public_key: string;
Expand All @@ -279,6 +287,8 @@ const transformUser = (
return {
id: user.id,
username: user.username,
firstname: user.firstname,
lastname: user.lastname,
// Camelcase public keys for response
publicKeys: user.public_keys
.map((k) => ({
Expand All @@ -302,6 +312,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 Down Expand Up @@ -329,6 +341,9 @@ export const createUser = async (
{
object: {
username: username,

firstname: firstName,
lastname: lastName,
public_keys: {
data: blockchainPublicKeys.map((b) => ({
blockchain: b.blockchain,
Expand Down Expand Up @@ -491,6 +506,35 @@ export async function updateUserAvatar({
return response.update_auth_users;
}

/**
* Update user's firstname and lastname
*/

export async function updateUserName(
userId: string,
firstname: string,
lastname: string
) {
const response = await chain("mutation")({
update_auth_users: [
{
where: {
id: { _eq: userId },
},
_set: {
firstname: firstname,
lastname: lastname,
},
},
{
affected_rows: true,
},
],
});

return response.update_auth_users;
}

export const getUserByPublicKeyAndChain = async (
publicKey: string,
blockchain: Blockchain
Expand Down
21 changes: 20 additions & 1 deletion backend/native/backpack-api/src/routes/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getUsersByPublicKeys,
getUsersMetadata,
updateUserAvatar,
updateUserName,
} from "../../db/users";
import { getOrcreateXnftSecret } from "../../db/xnftSecrets";
import { logger } from "../../logger";
Expand Down Expand Up @@ -124,7 +125,7 @@ router.get("/jwt/xnft", extractUserId, async (req, res) => {
* Create a new user.
*/
router.post("/", async (req, res) => {
const { username, waitlistId, blockchainPublicKeys } =
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 Expand Up @@ -255,6 +258,22 @@ router.get("/me", extractUserId, async (req: Request, res: Response) => {
return res.status(404).json({ msg: "User not found" });
});

/**
* Updates firstname and lastname of user in database
*/

router.put(
"/changeName",
extractUserId,
async (req: Request, res: Response) => {
const id = req.id || "";
const firstname = req.body.firstname;
const lastname = req.body.lastname;
await updateUserName(id, firstname, lastname);
return res.status(201).end();
}
);

router.get("/primarySolPubkey/:username", async (req, res) => {
const username = req.params.username;
try {
Expand Down
3 changes: 3 additions & 0 deletions backend/native/backpack-api/src/validation/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const BaseCreateUser = z.object({
/^[a-z0-9_]{3,15}$/,
"should be between 3-15 characters and can only contain numbers, letters, and underscores."
),
firstName: z.string(),
lastName: z.string(),

inviteCode: z
.string()
.regex(
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
19 changes: 19 additions & 0 deletions backend/native/zeus/src/zeus/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,10 @@ export const AllTypesProps: Record<string, any> = {
_or: "auth_users_bool_exp",
created_at: "timestamptz_comparison_exp",
dropzone_public_key: "auth_public_keys_bool_exp",
firstname: "String_comparison_exp",
id: "uuid_comparison_exp",
invitation: "auth_invitations_bool_exp",
lastname: "String_comparison_exp",
public_keys: "auth_public_keys_bool_exp",
public_keys_aggregate: "auth_public_keys_aggregate_bool_exp",
referred_users: "auth_users_bool_exp",
Expand All @@ -774,22 +776,31 @@ export const AllTypesProps: Record<string, any> = {
},
auth_users_constraint: "enum" as const,
auth_users_insert_input: {
avatar_nft: "citext",
created_at: "timestamptz",
id: "uuid",
invitation: "auth_invitations_obj_rel_insert_input",
invitation_id: "uuid",
last_active_at: "timestamptz",
public_keys: "auth_public_keys_arr_rel_insert_input",
referred_users: "auth_users_arr_rel_insert_input",
referrer: "auth_users_obj_rel_insert_input",
referrer_id: "uuid",
updated_at: "timestamptz",
username: "citext",
},
auth_users_max_order_by: {
created_at: "order_by",
firstname: "order_by",
id: "order_by",
lastname: "order_by",
username: "order_by",
},
auth_users_min_order_by: {
created_at: "order_by",
firstname: "order_by",
id: "order_by",
lastname: "order_by",
username: "order_by",
},
auth_users_obj_rel_insert_input: {
Expand All @@ -804,8 +815,10 @@ export const AllTypesProps: Record<string, any> = {
auth_users_order_by: {
created_at: "order_by",
dropzone_public_key_aggregate: "auth_public_keys_aggregate_order_by",
firstname: "order_by",
id: "order_by",
invitation: "auth_invitations_order_by",
lastname: "order_by",
public_keys_aggregate: "auth_public_keys_aggregate_order_by",
referred_users_aggregate: "auth_users_aggregate_order_by",
referrer: "auth_users_order_by",
Expand Down Expand Up @@ -2084,8 +2097,10 @@ export const ReturnTypes: Record<string, any> = {
auth_users: {
created_at: "timestamptz",
dropzone_public_key: "auth_public_keys",
firstname: "String",
id: "uuid",
invitation: "auth_invitations",
lastname: "String",
public_keys: "auth_public_keys",
public_keys_aggregate: "auth_public_keys_aggregate",
referred_users: "auth_users",
Expand All @@ -2104,12 +2119,16 @@ export const ReturnTypes: Record<string, any> = {
},
auth_users_max_fields: {
created_at: "timestamptz",
firstname: "String",
id: "uuid",
lastname: "String",
username: "citext",
},
auth_users_min_fields: {
created_at: "timestamptz",
firstname: "String",
id: "uuid",
lastname: "String",
username: "citext",
},
auth_users_mutation_response: {
Expand Down
Loading