mirror of
https://github.com/colanode/colanode.git
synced 2026-05-18 05:05:03 +02:00
Implement new changes in seed script
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import FormData from 'form-data';
|
||||
import axios from 'axios';
|
||||
import { LoginOutput } from '@colanode/core';
|
||||
import { LoginSuccessOutput } from '@colanode/core';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -38,14 +38,20 @@ const uploadAvatar = async (
|
||||
}
|
||||
};
|
||||
|
||||
const createAccount = async (account: FakerAccount): Promise<LoginOutput> => {
|
||||
const url = `${SERVER_DOMAIN}/client/v1/accounts/register/email`;
|
||||
const { data } = await axios.post<LoginOutput>(url, {
|
||||
const createAccount = async (
|
||||
account: FakerAccount
|
||||
): Promise<LoginSuccessOutput> => {
|
||||
const url = `${SERVER_DOMAIN}/client/v1/accounts/emails/register`;
|
||||
const { data } = await axios.post<LoginSuccessOutput>(url, {
|
||||
name: account.name,
|
||||
email: account.email,
|
||||
password: account.password,
|
||||
});
|
||||
|
||||
if (data.type !== 'success') {
|
||||
throw new Error('Failed to create account');
|
||||
}
|
||||
|
||||
const avatarPath = path.resolve(`src/seed/avatars/${account.avatar}`);
|
||||
const avatarId = await uploadAvatar(data.token, avatarPath);
|
||||
data.account.avatar = avatarId;
|
||||
@@ -69,7 +75,7 @@ const createAccount = async (account: FakerAccount): Promise<LoginOutput> => {
|
||||
|
||||
const createMainAccountAndWorkspace = async (
|
||||
account: FakerAccount
|
||||
): Promise<LoginOutput> => {
|
||||
): Promise<LoginSuccessOutput> => {
|
||||
const login = await createAccount(account);
|
||||
const workspace = login.workspaces[0];
|
||||
if (!workspace) {
|
||||
@@ -104,7 +110,7 @@ const createMainAccountAndWorkspace = async (
|
||||
};
|
||||
|
||||
const inviteAccountsToWorkspace = async (
|
||||
mainAccount: LoginOutput,
|
||||
mainAccount: LoginSuccessOutput,
|
||||
otherFakerAccounts: FakerAccount[]
|
||||
) => {
|
||||
const workspace = mainAccount.workspaces[0];
|
||||
|
||||
@@ -15,14 +15,16 @@ import {
|
||||
LocalCreateTransaction,
|
||||
CreateMessageMutation,
|
||||
entryAttributesSchema,
|
||||
MessageType,
|
||||
TransactionOperation,
|
||||
} from '@colanode/core';
|
||||
import { encodeState, YDoc } from '@colanode/crdt';
|
||||
import { faker } from '@faker-js/faker';
|
||||
|
||||
import { User } from './types';
|
||||
|
||||
const MESSAGES_PER_CONVERSATION = 2000;
|
||||
const RECORDS_PER_DATABASE = 2000;
|
||||
const MESSAGES_PER_CONVERSATION = 500;
|
||||
const RECORDS_PER_DATABASE = 500;
|
||||
|
||||
export class NodeGenerator {
|
||||
constructor(
|
||||
@@ -253,11 +255,11 @@ export class NodeGenerator {
|
||||
id: generateId(IdType.Mutation),
|
||||
data: {
|
||||
id: messageId,
|
||||
type: 'standard',
|
||||
entryId: conversationId,
|
||||
parentId: conversationId,
|
||||
rootId,
|
||||
content: {
|
||||
attributes: {
|
||||
type: MessageType.Standard,
|
||||
blocks: this.buildMessageContent(messageId),
|
||||
},
|
||||
createdAt: new Date().toISOString(),
|
||||
@@ -919,7 +921,7 @@ export class NodeGenerator {
|
||||
|
||||
return {
|
||||
id: generateId(IdType.Transaction),
|
||||
operation: 'create',
|
||||
operation: TransactionOperation.Create,
|
||||
data: encodeState(update),
|
||||
entryId,
|
||||
rootId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LoginOutput, Mutation } from '@colanode/core';
|
||||
import { LoginSuccessOutput, Mutation } from '@colanode/core';
|
||||
|
||||
export type FakerAccount = {
|
||||
name: string;
|
||||
@@ -8,7 +8,7 @@ export type FakerAccount = {
|
||||
};
|
||||
|
||||
export type User = {
|
||||
login: LoginOutput;
|
||||
login: LoginSuccessOutput;
|
||||
userId: string;
|
||||
mutations: Mutation[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user