diff --git a/backend/scripts/delete-user-fields.sql b/backend/scripts/delete-user-fields.sql new file mode 100644 index 0000000000..1b1a0f4705 --- /dev/null +++ b/backend/scripts/delete-user-fields.sql @@ -0,0 +1,14 @@ +update users set data = data + - 'name' + - 'username' + - 'profitCached' + - 'portfolioHistory' + - 'createdTime' + - 'balance' + - 'spiceBalance' + - 'totalDeposits' + - 'totalCashDeposits' + - 'metricsLastUpdated' + - 'marketsCreatedThisWeek' + - 'lastPingTime' + - 'bountyTxns' \ No newline at end of file diff --git a/backend/shared/src/create-user-main.ts b/backend/shared/src/create-user-main.ts index 38a6adaf19..8e3b2eef90 100644 --- a/backend/shared/src/create-user-main.ts +++ b/backend/shared/src/create-user-main.ts @@ -35,6 +35,7 @@ import { STARTING_BALANCE } from 'common/economy' import { ValidatedAPIParams } from 'common/api/schema' import { APIError } from 'common/api/utils' import { onCreateUser } from 'shared/helpers/on-create-user' +import { convertPrivateUser, convertUser } from 'common/supabase/users' export const createUserMain = async ( props: ValidatedAPIParams<'createuser'>, @@ -108,17 +109,9 @@ export const createUserMain = async ( throw new APIError(403, 'Username already taken', { username }) // Only undefined prop should be fromLove - const user: User = removeUndefinedProps({ + const userData: Partial = removeUndefinedProps({ id: userId, - name, - username, avatarUrl, - balance: 0, - cashBalance: 0, - spiceBalance: 0, - totalDeposits: 0, - totalCashDeposits: 0, - createdTime: Date.now(), nextLoanCached: 0, streakForgiveness: 1, shouldShowWelcome: true, @@ -144,11 +137,11 @@ export const createUserMain = async ( blockedGroupSlugs: [], } - await insert(tx, 'users', { - id: user.id, - name: user.name, - username: user.username, - data: user, + const userRow = await insert(tx, 'users', { + id: userId, + name: name, + username: username, + data: userData, }) const startingBonusTxn: Omit< @@ -156,7 +149,7 @@ export const createUserMain = async ( 'id' | 'createdTime' | 'fromId' > = { fromType: 'BANK', - toId: user.id, + toId: userId, toType: 'USER', amount: STARTING_BALANCE, token: 'M$', @@ -165,14 +158,14 @@ export const createUserMain = async ( } await runTxnFromBank(tx, startingBonusTxn) - await insert(tx, 'private_users', { + const privateUserRow = await insert(tx, 'private_users', { id: privateUser.id, data: privateUser, }) return { - user, - privateUser, + user: convertUser(userRow), + privateUser: convertPrivateUser(privateUserRow), } })