0
    import conf from "@/conf/config";
import { Client, Databases, Account, ID } from "appwrite";
import appwriteService from "@/appwrite/config";


type createProject = {
    name: string,
    description: string,
    logo: string,
    url: string,
    userId: string
}

const dbClient = new Client()


dbClient.setEndpoint(conf.appwriteUrl).setProject(conf.appwriteProjectId);


export const db = new Databases(dbClient)

export class dbService{

    async createProject({name, description, logo, url, userId}: createProject) {
        const account = new Account(dbClient);
        const user = (await account.get()).$id 
        try {

            const project = await db.createDocument(`${conf.appwriteDbId}`,`${conf.appwriteCollectionId}`, ID.unique(),{
                name,
                description,
                logo,
                url,
                userId: user || ''
            },[]
            )
        } catch (error:any) {
            throw error
        }
    }

    
}

const dbServices = new dbService()
export default dbServices

While I try to create a document in the appwrite database. It should also save the userId who created the document. On this 15th line async createProject({name, description, logo, url, userId}: createProject it shows that the 'userId' is declared but its value is never read. How do I fix this problem.

Ayush Parui
  • 13
  • 1
  • 4
  • ?? The error message is pretty clear: your code never looks at the value of the `userId` parameter. – Pointy Aug 17 '23 at 13:41
  • You get the `userId` from the parameters (and never use it) and `user` also seems to be the user-id (from the `account`): so which one do you want to use? – TmTron Aug 17 '23 at 13:42
  • I'm new to typescript, the only thing that I want is when someone creates a document it should also save the current users userId which we can get from account. So how do I fix this code? – Ayush Parui Aug 17 '23 at 14:55

1 Answers1

0

TypeScript is pointing out that you declared a userId parameter:

createProject({name, description, logo, url, userId}: createProject)

but you're not using it in your function. Since you're not using it, you can remove it:

type createProject = {
    name: string,
    description: string,
    logo: string,
    url: string
}

and

createProject({name, description, logo, url}: createProject)
Steven Nguyen
  • 452
  • 4
  • 4
  • The problem is that I want to save the current user's UserId in the Database while creating a document. That is the reason why I was using the UserID, so how do I fix it. – Ayush Parui Aug 21 '23 at 01:03
  • If you want to save it in a document, you need to pass it to createDocument(). Maybe you should pass userId instead of setting userId to user. – Steven Nguyen Aug 23 '23 at 06:28