How to add a "Delete" method in my Custom API Call with parameter

Hi everyone!

I created a new custom API to get some information and I would like to have also a Delete method.

I realized that if I customize a standard API Call (for example from Table ShoppingCartPattern -> Class CartPatterAdminApi, the function EnableDelete() can be used:

For Example:

This API Call works good and I get through my custom service the GET and DELETE methods.

    public class CCCCartPatternAdminApi : IApiProviderFor<PortalApiProject>, IApiProvider
    {
        public void Build(IApiBuilder builder)
        {
            builder.AddMethod(QBM.CompositionApi.Definition.ExtensionMethods.With(Method.Define("ccc/itshop/pattern/admin").WithDescription("Returns all IT shop patterns."), delegate (IMethod m)
            {
                m.Settings.SortOrder = -1;
            }).From<CCCShoppingCartPattern>().EnableRead()
                .EnableDelete()
                .WithResultColumns((CCCShoppingCartPattern p) => p.Ident_ShoppingCartPattern, (CCCShoppingCartPattern p) => p.UID_Person, (CCCShoppingCartPattern p) => p.Description, (CCCShoppingCartPattern p) => p.CCC_TotalNumberOfItems)
                .EnableUpdate()
                .WithWritableColumns((CCCShoppingCartPattern p) => p.Ident_ShoppingCartPattern, (CCCShoppingCartPattern p) => p.IsPublicPattern, (CCCShoppingCartPattern p) => p.UID_Person, (CCCShoppingCartPattern p) => p.Description));
        }
    }
}

But, I try with a Custom Table the same and I get the following error by generation the ccc paquet:

    public class CCCCartPatternDepApi : IApiProviderFor<PortalApiProject>, IApiProvider
    {
        public void Build(IApiBuilder builder)
        {

            builder.AddMethod(Method.Define("ccc/itshop/patterndep/dep/{uidpattern}").WithParameter("uidpattern", typeof(string), "Unique pattern identifier", null, null, isInQuery: false).WithDescription("Returns all deps for the IT shop pattern.")
            .From<CCCShoppingCartPatternDep>()
            .EnableRead()
            .EnableDelete()
            .EnableUpdate()
            .WithResultColumns((CCCShoppingCartPatternDep x) => x.CCC_UID_Department)
            .WithWhereClause((IRequest r) => r.Session.SqlFormatter().UidComparison("CCC_UID_ShoppingCartPattern", r.Parameters.Get<string>("uidpattern"))));
        }
    }
}

ERROR:

Error: The command generated the following console output:

> @imx-modules/imx-api-ccc@0.0.0 build
> ..\node_modules\.bin\tsc && ..\node_modules\.bin\rollup -c

src/lib/TypedClient.ts(17735,31): error TS2554: Expected 2-4 arguments, but got 1.

I checked and this error will not happen if I don´t add the line ".EnableDelete()".


Can someone please help me? 
How do you normally add "DELETE" API Calls?

Thank you in advance!
BR Fermín

  • HI there,

    I´ve just realized that I cannot add explicit a parameter in my Builder method to be able to get a DELETE API Call.

    By default with EnableDelete() will be generated with primary key.

    For example:

    builder.AddMethod(Method.Define("ccc/itshop/pattern/department/")
        .WithDescription("Deletes a dep for an IT shop pattern.")
        .From<CCCShoppingCartPatternDep>()
        .EnableRead()
        .EnableDelete()
    

    Info: Endpoint GET portal/ccc/itshop/pattern/department/del added.
    Info: Endpoint DELETE portal/ccc/itshop/pattern/department/del/{UID_CCCShoppingCartPatternDep} added.