System Information
- Strapi Version: 4.1.12
- Operating System: Linux-5.16.20-051620-generic-x86_64-with-glibc2.29
- Database: Postgresql
- Node Version: v16.14.2
- NPM Version: 8.5.0
- Yarn Version: 1.22.18
DESCRIPTION
I am building a custom controller for profile api but it is giving me a lot of error.
The Code
"use strict";
/**
* profile custom controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::profile.profile", ({ strapi }) => ({
async createMe(ctx) {
try {
let entity;
// Fetching authenticated users details
const user = ctx.state.user;
if (!user) {
return ctx.badRequest(null, [
{ message: [{ id: "No autorization token was found." }] },
]);
}
const data = ctx.request.body;
data["user"] = user;
entity = await strapi.entityService.create("api::profile.profile", {
data: data,
});
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return this.transformResponse(sanitizedEntity);
} catch (error) {
return ctx.badRequest("Internal API error", { realError: error });
}
},
async getMe(ctx) {
let entities;
const user = ctx.state.user;
if (!user) {
return ctx.badRequest(null, [
{ message: [{ id: "No autorization token was found." }] },
]);
}
var __user = {
data: {
id: ctx.state.user.id,
attributes: {
username: ctx.state.user.username,
email: ctx.state.user.email,
provider: ctx.state.user.provider,
confirmed: ctx.state.user.confirmed,
blocked: ctx.state.user.blocked,
createdAt: ctx.state.user.createdAt,
updatedAt: ctx.state.user.updatedAt,
beta: ctx.state.user.beta,
},
},
};
entities = await strapi.db.query("api::profile.profile").findMany({
where: {
$and: [
{
user: __user
},
],
},
});
return entities.map(async (entity) => {
await this.sanitizeOutput(entity, ctx);
});
},
async updateMe(ctx) {
return ctx.badRequest("Internal Server Error", {
message: "This api endpoint is under construction.",
});
},
}));
ERROR
While fetching http://localhost:1337/api/profiles/me/get
(Uses the getMe function as mentioned above.) it is returning
error: Undefined attribute level operator id
Error: Undefined attribute level operator id
at processAttributeWhere (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:82:13)
at processWhere (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:142:45)
at processNested (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:112:12)
at processWhere (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:155:25)
at processNested (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:112:12)
at /workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:126:39
at Array.map (<anonymous>)
at processWhere (/workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:126:28)
at /workspace/strapi-backened/backened/node_modules/@strapi/database/lib/query/helpers/where.js:104:29
at Array.map (<anonymous>)